StAX - 如何将 XMLInputFactory.IS_VALIDATING 设置为 true? [英] StAX - how to set XMLInputFactory.IS_VALIDATING to true?

查看:33
本文介绍了StAX - 如何将 XMLInputFactory.IS_VALIDATING 设置为 true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用 StAX 解析 XML 文档(仍处于学习阶段).在使用 XMLStreamReader 解析 XML 文档并使用 XMLStreamWriter 生成文档副本的过程中,我遇到了以下警告,表示为编写器输出中的注释:

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. -->

我理解警告的原因,但我希望它变成一个错误而不是默默地变成一个警告,所以我尝试将 XMLInputFactory.IS_VALIDATING 设置为 true:

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:

线程main"中的异常java.lang.IllegalArgumentException:isValidating not 的真值支持在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)

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?

谢谢!

推荐答案

看起来 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.

这篇关于StAX - 如何将 XMLInputFactory.IS_VALIDATING 设置为 true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆