StAX - 如何将 XMLInputFactory.IS_VALIDATING 设置为 true?
这是我第一次使用 StAX 来解析 XML 文档(仍处于学习阶段)。在使用 XMLStreamReader 解析 XML 文档并使用 XMLStreamWriter 生成文档副本的过程中,我遇到了以下警告,在编写器的输出中以注释形式表示:
<!-- Exception scanning External DTD Subset. True contents of DTD cannot be determined. Processing will continue as XMLInputFactory.IS_VALIDATING == false. -->
我理解警告的原因,但我希望它成为一个错误而不是默默地变成了一个警告,所以我尝试将 XMLInputFactory.IS_VALIDATING 设置为 true:
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.TRUE);
但上面的内容为我抛出了一个异常:
线程“main”中出现异常 java.lang.IllegalArgumentException: isValidating 的真实值不是 支持于 com.sun.org.apache.xerces.internal.impl.PropertyManager.setProperty(PropertyManager.java:150) 在 com.sun.xml.internal.stream.XMLInputFactoryImpl.setProperty(XMLInputFactoryImpl.java:257) 在 com.test.test2.helper.SgmlDocumentParser.parse(SgmlDocumentParser.java:83) 在 com.test.test2.helper.Test.main(Test.java:66)
那么我的方法有什么问题呢?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 Sun 的 StAX 实现不支持 DTD 验证。您可以尝试使用 Woodstox 代替,它似乎支持验证。
It looks like Sun's StAX implementation just doesn't support DTD validation. You could try using Woodstox instead, it appears to support validation.