简体   繁体   English

错误:“尚未声明前缀“xsi”的命名空间。

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

Why am I getting this error:为什么我收到此错误:

ERROR: 'Namespace for prefix 'xsi' has not been declared.'错误:“尚未声明前缀“xsi”的命名空间。

Here is my Java code:这是我的Java代码:

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.这段代码运行正常,直到我尝试抛出转换器异常,同时将 XML 文件转换为 HTML 仅用于实验。 I need to create an xml file with the format:我需要使用以下格式创建一个 xml 文件:

<?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:我已经从代码中删除了变压器部分,但我在 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.要使 XML 文档格式正确,必须声明所有使用的名称空间前缀。

Simply declare the xsi namespace prefix on the root element of your XML,只需在 XML 的根元素上声明xsi命名空间前缀,

<?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.请注意,您同样必须定义spml命名空间前缀。

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."我遇到了同样的错误“AxisFault faultCode: { http://schemas.xmlsoap.org/soap/envelope/ }Server faultSubcode: faultString: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been denied.” 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.在从coldfusion 9 服务器调用soap web 服务时,由于我不得不花费更多时间,错误无法快速解决,最终发现由于提供给webservice 参数的日期值不正确,它引发了不同的问题。 Whenever we got this issue please check input values that are supplying to the webservcie parameters.每当我们遇到此问题时,请检查提供给 webservcie 参数的输入值。 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.在我的情况下,由于日期时间格式 2015-03-04T00:00:00.000Z(它是 ISO-8601 日期表示的一部分),问题发生了,2015-03-04 00:00 解决了这个问题。 For example for datetime If I provide string(xxxx), coldfusion axis webservice shows te irrelevant error --Namespace for prefix 'xsi' has not been declared....例如对于日期时间如果我提供字符串(xxxx),coldfusion 轴网络服务会显示不相关的错误 -- 前缀“xsi”的命名空间尚未声明....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尚未声明前缀“ xsi”的命名空间 - Namespace for prefix 'xsi' has not been declared 属性上的 Java XML 转换器错误:尚未声明前缀“req”的命名空间 - Java XML transformer error on attribute : Namespace for prefix 'req' has not been declared Java XML 和 XSLT 转换错误:尚未声明前缀“m”的命名空间 - Java XML and XSLT transformation error: Namespace for prefix 'm' has not been declared 尚未声明带有前缀“ uml”的JDOM2命名空间 - JDOM2 Namespace with prefix 'uml' has not been declared maven 发布:准备命名空间前缀“xsi”与元素声明的附加命名空间冲突 - maven release:prepare namespace prefix “xsi” collides with an additional namespace declared by the element XMLStreamException:名称空间URI尚未绑定到前缀IBM jre - XMLStreamException: The namespace URI has not been bound to a prefix,IBM jre 使用Java和xPath在OWL / XML文件中提取节点后,命名空间前缀未声明错误 - Namespace prefix not declared error after extracting a node in OWL/XML file with Java & xPath 何时声明destroy()? - When the destroy() has been declared? 如果存在xsi:type和不同的名称空间前缀,则xmlunit.Diff返回similar = false - xmlunit.Diff returns similar=false if there is a xsi:type and a different namespace prefix 删除元素中的xsi命名空间 - Remove xsi namespace in element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM