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!
It looks like Sun's StAX implementation just doesn't support DTD validation. You could try using Woodstox instead, it appears to support validation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With