;
SAXParserFactory spf = new WstxSAXParserFactory();
spf.setNamespaceAware(true);
SAXParser sp = spf.newSAXParser();
DefaultHandler h = new DefaultHandler();
/* First: let's verify that we get an exception for
* unresolved reference...
*/
try {
sp.parse(new InputSource(new StringReader(XML)), h);
} catch (SAXException e) {
verifyException(e, "No such file or directory");
}
// And then with dummy resolver; should work ok now
sp = spf.newSAXParser();
sp.getXMLReader().setEntityResolver(new MyResolver(" "));
h = new DefaultHandler();
try {
sp.parse(new InputSource(new StringReader(XML)), h);
} catch (SAXException e) {
fail("Should not have failed with entity resolver, got ("+e.getClass()+"): "+e.getMessage());
}