I'm reading a XML message
string from a queue of Websphere MQ and the XML string contains something like:
<myRoot TransactionId="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mySchema.xsd">
.....
</myRoot>
When I parse the XML string to DOM, I set the parser to validate the XML in
following way:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new DefaultHandler());
Document dom = builder.parse(new InputSource(new StringReader(xmlString)));
I got following error when the program runs:
org.xml.sax.SAXException: Parsing Error
Line: 2
URI: null
Message: Element type "myRoot" must be declared.
I think it is because that parser could not find mySchema.xsd file. Where should I put mySchema.xsd file? Thanks.