Using SAX and Java I want to parse an XML string but get this exception
[Fatal Error] :1:92: The prefix "xsi" for attribute "xsi:type" associated with an element type "device" is not bound.
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(false);
factory.setValidating(false);
SAXParser parser = factory.newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
handler = new ConfigHandler();
xmlReader = XMLReaderFactory.createXMLReader();
// assign our handler
xmlReader.setContentHandler(handler);
// perform the synchronous parse
xmlReader.parse(new InputSource(new StringReader(xml)));
} catch (Exception e) {
e.printStackTrace();
}
Here is the xml
<device xsi:type="axl:XIPPhone" ctiid="182" uuid="{20a9f66a-fb1f-6981-5851-1474258054dc}">
<fullConfig>true</fullConfig>
<portalDefaultServer>serveraxd.lestry.com</portalDefaultServer>
<deviceProtocol>SOORTY</deviceProtocol>
..
..
</device>
I am not able to change the XML content in this case.
Exactly as the error message says, you have not provided a namespace declaration for the xsi: prefix. Add
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
to your top-level element (the <device>
element).