解析XML格式不正确 [英] Parse malformed XML
问题描述
我想一块(可能)畸形的HTML加载到如下的对象,但它失败XMLExceptions ......因为有多余的打开/关闭标签,和畸形XML标记,如< IMG>
而不是< IMG />
I'm trying to load a piece of (possibly) malformed HTML into an XMLDocument object, but it fails with XMLExceptions... since there are extra opening/closing tags, and malformed XML tags such as <img >
instead of <img />
如何做我得到的与XML数据中所有的错误解析?有没有办法,我可以解析之前适用,纠正这些错误的XML验证?还是会处理异常解析任何可以解析
How do I get the XML to parse with all the errors in the data? Is there any XML validator that I can apply before parsing, to correct these errors? Or would handling the exception parse whatever can be parsed?
推荐答案
的 HTML敏捷性包将解析HTML,而不是XHTML,而且是相当宽容。如果你已经使用的XmlDocument
的对象模型会很熟悉。
The HTML Agility Pack will parse html, rather than xhtml, and is quite forgiving. The object model will be familiar if you've used XmlDocument
.
这篇关于解析XML格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!