简体   繁体   中英

ERROR: 'Namespace for prefix 'xsi' has not been declared.'

Why am I getting this error:

ERROR: 'Namespace for prefix 'xsi' has not been declared.'

Here is my Java code:

package com.emp.ma.jbl.nsnhlrspmlpl.nsnhlrspmlpl.internal.action;
import com.emp.ma.util.xml.XMLDocument;
import com.emp.ma.util.xml.XMLDocumentBuilder;

 public class yay {            
        public static void main(String[] args) {
            XMLDocument xmldoc = XMLDocumentBuilder.newDocument().addRoot("spml:modifyRequest");
            xmldoc.gotoRoot().addTag("modification").addText("");
            xmldoc.gotoChild("modification").addTag("valueObject").addText("");
            xmldoc.gotoChild("valueObject").addAttribute("xsi:type","halo");
            System.out.println(xmldoc);
        }            
    }

This code was functioning properly until I tried throwing transformer exception whilst converting XML file to HTML for experimenting only. I need to create an xml file with the format:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<spml:modifyRequest>   
  <modification>
    <valueObject xsi:type="halo">
    </valueObject>   
  </modification>
</spml:modifyRequest>

I removed the transformer part from the code already and yet I'm getting this error in eclipse:

 ERROR:  'Namespace for prefix 'xsi' has not been declared.'
    Exception in thread "main" com.emp.ma.util.xml.XMLDocumentException: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared.
        at com.emp.ma.util.xml.XMLDocumentImpl.toResult(XMLDocumentImpl.java:1244)
        at com.emp.ma.util.xml.XMLDocumentImpl.toStream(XMLDocumentImpl.java:1314)
        at com.emp.ma.util.xml.XMLDocumentImpl.toString(XMLDocumentImpl.java:1336)
        at com.emp.ma.util.xml.XMLDocumentImpl.toString(XMLDocumentImpl.java:1325)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.emp.ma.util.xml.XMLDocumentBuilder$XMLDocumentHandler.invoke(XMLDocumentBuilder.java:55)
        at $Proxy1.toString(Unknown Source)
        at java.lang.String.valueOf(Unknown Source)
        at java.io.PrintStream.println(Unknown Source)
        at com.emp.ma.jbl.nsnhlrspmlpl.nsnhlrspmlpl.internal.action.yay.main(yay.java:13)
    Caused by: javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared.
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at com.emp.ma.util.xml.XMLDocumentImpl.toResult(XMLDocumentImpl.java:1242)
        ... 12 more
    Caused by: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared.
        at com.sun.org.apache.xml.internal.serializer.SerializerBase.getNamespaceURI(Unknown Source)
        at com.sun.org.apache.xml.internal.serializer.SerializerBase.addAttribute(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
    ... 15 more

I'm stuck because of this one exception and I don't know how to undo this. Please do help. Like i said, it was functioning properly before trying this experiment of mine, if possible how do I remove this transformer integration. I've tried changing workspace as well -- still not working.

For an XML document to be well-formed, all used namespace prefixes must be declared.

Simply declare the xsi namespace prefix on the root element of your XML,

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<spml:modifyRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   
  <modification>
    <valueObject xsi:type="halo">
    </valueObject>   
  </modification>
</spml:modifyRequest>

and your error will go away.

Note that you'll similarly have to define the spml namespace prefix.

I got the same error "AxisFault faultCode: { http://schemas.xmlsoap.org/soap/envelope/ }Server faultSubcode: faultString: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared." while calling the soap web service from coldfusion 9 server, as the error does not resolve quickly as I had to spent more time, finnaly found that due to the incorrect date value supplying to the webservice parameters, it throws different issue. Whenever we got this issue please check input values that are supplying to the webservcie parameters. In my case due to the datetime format 2015-03-04T00:00:00.000Z(It's a part of ISO-8601 date representation), issue happened, 2015-03-04 00:00 resolves the issue. For example for datetime If I provide string(xxxx), coldfusion axis webservice shows te irrelevant error --Namespace for prefix 'xsi' has not been declared....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM