如何在运行时在java的xpath中禁用dtd?
我的文件中有 dtd,但无法删除它。 当我尝试用 Java 解析它时,我得到“Caused by: java.net.SocketException: Network is unreachable: connect”,因为它是远程 dtd。 我可以以某种方式禁用 dtd 检查吗?
I got dtd in file and I cant remove it. When i try to parse it in Java I get "Caused by: java.net.SocketException: Network is unreachable: connect", because its remote dtd. can I disable somehow dtd checking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该能够指定自己的 EntityResolver,或者使用解析器的特定功能? 请参阅此处了解一些方法。
一个更完整的例子:
和xpath用法:
希望这有帮助......
You should be able to specify your own EntityResolver, or use specific features of your parser? See here for some approaches.
A more complete example:
And xpath usage:
Hope this helps...
这对我有用:
This worked for me:
我以前也遇到过这个问题。 我通过下载并存储 DTD 的本地副本,然后根据本地副本进行验证来解决这个问题。 您需要编辑 XML 文件以指向本地副本。
更多信息如下:http://www.w3schools.com/dtd/dtd_intro.asp
我认为您还可以在解析器中手动将某种 validateOnParse 属性设置为“false”。 取决于您使用什么库来解析 XML。
更多信息请参见:http://www.w3schools.com/dtd/dtd_validation.asp
I had this problem before. I solved it by downloading and storing a local copy of the DTD and then validating against the local copy. You need to edit the XML file to point to the local copy.
Little more info here: http://www.w3schools.com/dtd/dtd_intro.asp
I think you can also manually set some sort of validateOnParse property to "false" in your parser. Depends on what library you're using to parse the XML.
More info here: http://www.w3schools.com/dtd/dtd_validation.asp