我想解析一个XML文件。它在创建对象时抛出异常:
Document doc = builder.parse("Response.xml");
例外:
[Fatal Error] Response.xml:63:67: The prefix "UDF" for element "UDF:RTSIDUDF.LIST" is not bound.
Exception in thread "main" org.xml.sax.SAXParseException: The prefix "UDF" for element "UDF:RTSIDUDF.LIST" is not bound.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
at tallyreqandresponse.Ledger.main(Ledger.java:38)
Java Result: 1
示例xml代码:
<A>
<LANGUAGENAME.LIST>
<NAME.LIST TYPE="String">
<NAME>ABC India (P) Ltd.,</NAME>
</NAME.LIST>
<LANGUAGEID TYPE="Number"> 1033</LANGUAGEID>
<UDF:RTSIDUDF.LIST DESC="`RTSIDUDF`" ISLIST="YES" TYPE="Number">
<UDF:RTSIDUDF DESC="`RTSIDUDF`"> 1387</UDF:RTSIDUDF>
</UDF:RTSIDUDF.LIST>
</LANGUAGENAME.LIST>
</A>
请帮助我。
编辑注释:添加了LANGUAGENAME.LIST开始标记
答案 0 :(得分:2)
您的输入标记不是命名空间格式良好的XML,因此XML解析器会拒绝它。您需要使用例如
来修复输入<A>
<NAME.LIST TYPE="String">
<NAME>ABC India (P) Ltd.,</NAME>
</NAME.LIST>
<LANGUAGEID TYPE="Number"> 1033</LANGUAGEID>
<UDF:RTSIDUDF.LIST xmlns:UDF="http://example.com/" DESC="`RTSIDUDF`" ISLIST="YES" TYPE="Number">
<UDF:RTSIDUDF DESC="`RTSIDUDF`"> 1387</UDF:RTSIDUDF>
</UDF:RTSIDUDF.LIST>
</LANGUAGENAME.LIST>
</A>
答案 1 :(得分:1)