StAX - how to set XMLInputFactory.IS_VALIDATING to true?

this is my first time using StAX to parse XML documents (still in training). During the process of parsing an XML document using XMLStreamReader and creating a copy of the document using XMLStreamWriter, I found the following warning, presented as a comment on the output of the record:

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

I understood the reason for the warning, but I wanted it to become a mistake, and not tacitly become a warning, so I tried to set XMLInputFactory.IS_VALIDATING to true:

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

But the above made an exception for me:

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

So what is wrong with my approach?

Thanks!

+5
source share
1 answer

It seems that the Sun StAX implementation simply does not support DTD validation. You could try using Woodstox , it seems to support validation.

+5
source

All Articles