Java DocumentBuilder.parse会引发错误";前缀为;";对于“元素”;c:de";不受约束。”;
我得到的错误是“元素“c:de”的前缀“c”未绑定”。任何提示都将非常感谢Java DocumentBuilder.parse会引发错误";前缀为;";对于“元素”;c:de";不受约束。”;,java,xml,dom,Java,Xml,Dom,我得到的错误是“元素“c:de”的前缀“c”未绑定”。任何提示都将非常感谢 javax.xml.parsers.DocumentBuilderFactory fac = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl( ); fac.setNamespaceAware(true); org.w3c.dom.Document d = null; javax.xml.parsers.DocumentBuilder builder = fac
javax.xml.parsers.DocumentBuilderFactory fac = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl( );
fac.setNamespaceAware(true);
org.w3c.dom.Document d = null;
javax.xml.parsers.DocumentBuilder builder = fac.newDocumentBuilder();
d = builder.parse("C:/my_folder/my_file.xml"); //the error rises in this line
my_file.xml完全粘贴在这里
<?xml version="1.0" encoding="UTF-8"?>
<c:de format="N" lengthField="0" maxLength="012" minLength="012" name="AMOUNT, TRANSACTION" number="004" subFields="00"/>
您的XML在技术上是无效的 命名空间前缀
c
“必须与命名空间声明中的命名空间URI引用相关联。”。例如,这将起作用:
<?xml version="1.0" encoding="UTF-8"?>
<c:de xmlns:c="http://localhost/" format="N" lengthField="0" maxLength="012" minLength="012" name="AMOUNT, TRANSACTION" number="004" subFields="00"/>
注意添加了
xmlns:c
属性。此属性中使用的URI应该是正确标识要使用的名称空间的URI。我建议您阅读有关XML名称空间的内容。谢谢您的建议。谢谢。你知道我该如何设置这个问题的答案吗?@user79885,答案左边应该有一个复选标记的轮廓。如果单击,则应填写绿色并将其标记为已接受答案。谢谢你这么做,因为它会给我一些分数,并告诉那些在未来寻找这个问题的人,这个问题已经得到了回答。