Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to disable validation against DTD while unmarshalling

Jpleau-OracleSep 23 2008
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 21 2008
Added on Sep 23 2008
0 comments
3,259 views