解析XML格式不正确 [英] Parse malformed XML

查看:859
本文介绍了解析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屋!

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