开发者

StAX - how to set XMLInputFactory.IS_VALIDATING to true?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜