問題描述
我正在嘗試將一段(可能)格式錯誤的 HTML 加載到 XMLDocument 對象中,但它因 XMLExceptions 而失敗...因為有額外的開始/結(jié)束標(biāo)記,以及格式錯誤的 XML 標(biāo)記,例如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 解析數(shù)據(jù)中的所有錯誤?在解析之前是否可以應(yīng)用任何 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 Agility Pack 將解析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
.
這篇關(guān)于解析格式錯誤的 XML的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!