使用xml.Load打开HTML文档 [英] Open an HTML Document with xml.Load
本文介绍了使用xml.Load打开HTML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打开一个HTML文档(作为从StreamReader或网络获取的字符串),通过以下方式创建XMLDocument:
I'd like to open an HTML document (as a string retrieved from a StreamReader, from the web), by creating a XMLDocument this way:
XmlDocument doc = new XmlDocument
doc.Load(string containing the retrieved document).
但是由于HTML文档包含此标题:
But since the HTML doc contains this head:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
它告诉我该文档无效...有任何解决方法吗?
It tells me that the document is invalid... Any way to workaround this?
推荐答案
普通的html,即使它是有效的html,也不是有效的xml.
Normal html, even if it's valid html, is not valid xml.
有一个名为HtmlAgilityPack的库,它是一个流行的第三方开源库,可用于解决此问题:
There is a library called HtmlAgilityPack which is a popular 3rd party open source library that you can use to solve this problem:
这篇关于使用xml.Load打开HTML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文