I want to parse a XML file. It throws the Exception while creating object:
Document doc = builder.parse("Response.xml");
Exception:
[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
Sample xml Code:
<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>
Kindly help me out of it.
Edit Note: Added LANGUAGENAME.LIST Opening tag
Your input markup is not namespace well-formed XML so it is rejected by the XML parser. You need to fix the input with eg
<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>
Beside the missing namespace definition it also seems that there is a mismatched tag:
</LANGUAGENAME.LIST>
has no corresponding opening tag.
If you Google xml namespaces
you get plenty of good links - have a look here for example.
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.