简体   繁体   English

带有DOCTYPE声明的XPathDocument行为

[英]XPathDocument behavior with DOCTYPE declaration

I use XPathDocument to parse an XML file, but if there's a doctype declaration , when I initializes a new instance of the XPathDocument class passing the path of the file, that contains the XML data, to its constructor, my application tries to connect to internet (probably to verify the correctness of the XML data) and remains blocked for a long period of time. 我使用XPathDocument解析XML文件,但是如果有doctype声明 ,当我初始化XPathDocument类的新实例时,将包含XML数据的文件路径传递到其构造函数,则我的应用程序尝试连接到Internet (可能是为了验证XML数据的正确性),并且长时间处于阻止状态。 This does not occur if I delete the doctype declaration from the XML file. 如果我从XML文件中删除doctype声明,则不会发生这种情况。 XmlDocument.Load method has the same behavior. XmlDocument.Load方法具有相同的行为。 How can I fix this problem? 我该如何解决这个问题?

Thanks. 谢谢。

If you use the XPathDocument constructor that takes an XmlReader as its input, you can set an XmlResolver on the XmlReader. 如果使用以XmlReader作为输入的XPathDocument构造函数,则可以在XmlReader上设置XmlResolver Then you can set the resolver to recognise the SVG doctype and supply a local copy of the SVG DTD. 然后,您可以设置解析器以识别SVG文档类型,并提供SVG DTD的本地副本。

Similarly, XmlDocument can also be given an XmlResolver before calling the Load method. 同样,在调用Load方法之前,也可以给XmlDocument一个XmlResolver。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM