How to disable validation against DTD while unmarshalling
Hi All
I am relatively new to XML and JAXB. I have a tool that needs to run offline, however the XML documents that are being read in are automatically being validated against the DTD even though I have specified unmarshaller.setValidating(false). How can I completely diable validation while offline? Here is my code:
context = JAXBContext.newInstance("my.xmlobjects.package");
Unmarshaller u = context.createUnmarshaller();
u.setValidating(false);
testLog = (TestLog) u.unmarshal(new File("/path/to/my/file.xml"));
I've also tried a suggestion I saw on another forum (note that I know nothing about SAX, I've been trying to make sense of the documentation):
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(false);
SAXParser saxParser = parserFactory.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
EntityResolver entityResolver = new EntityResolver()
{
public InputSource resolveEntity (String publicId, String systemId)
{
return null;
}
};
xmlReader.setEntityResolver(entityResolver);
InputSource source = new InputSource(new FileInputStream("/path/to/my/file.xml");
SAXSource saxSource = new SAXSource(xmlReader, source);
context = JAXBContext.newInstance("my.xmlobjects.package");
Unmarshaller u = context.createUnmarshaller();
u.setValidating(false);
testLog = (TestLog) u.unmarshal(saxSource);
Both of these work when connected, but fail when disconnected from the internet. Is there an Oracle specific property that needs to be set here?
Thanks
Jeff