我想解析XML文件。它拋出異常創建對象:使用Java中的XPath解析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打開標籤
您需要具有UDF名稱空間描述的xmlns。 – yatul