Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StAX - how to set XMLInputFactory.IS_VALIDATING to true?

Tags:

this is my first time using StAX for parsing XML documents (still in the learning stage). During the process to parse an XML document using XMLStreamReader and generate a copy of the document using XMLStreamWriter, I encountered the following warning represented as a comment in the output of the writer:

 <!-- Exception scanning External DTD Subset.  True contents of DTD cannot be determined.  Processing will continue as XMLInputFactory.IS_VALIDATING == false. -->

I understood the cause of the warning, but I wanted it to become an error rather than silently became a warning, so then I tried to set XMLInputFactory.IS_VALIDATING to true:

 XMLInputFactory factory = XMLInputFactory.newInstance();
 factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.TRUE);

But the above threw an exception for me:

Exception in thread "main" java.lang.IllegalArgumentException: true value of isValidating not supported at com.sun.org.apache.xerces.internal.impl.PropertyManager.setProperty(PropertyManager.java:150) at com.sun.xml.internal.stream.XMLInputFactoryImpl.setProperty(XMLInputFactoryImpl.java:257) at com.test.test2.helper.SgmlDocumentParser.parse(SgmlDocumentParser.java:83) at com.test.test2.helper.Test.main(Test.java:66)

So what is wrong with my approach?

Thanks!

like image 338
His Avatar asked Nov 02 '09 01:11

His


1 Answers

It looks like Sun's StAX implementation just doesn't support DTD validation. You could try using Woodstox instead, it appears to support validation.

like image 86
Lachlan Avatar answered Oct 12 '22 23:10

Lachlan