【问题标题】:Loading HTML page as XML将 HTML 页面加载为 XML
【发布时间】:2011-01-22 18:18:23
【问题描述】:

我用它来通过 XML 加载 HTML 页面

Dim xmlDoc As New XmlDocument()
xmlDoc.Load(Server.MapPath("index.htm"))

或者

Dim xmldoc As XDocument
xmldoc = XDocument.Load(Server.MapPath("index.htm"))

但我遇到了一些错误,例如:

  • Expecting an internal subset or the end of the DOCTYPE declaration. Line 2, position 14;
  • '>' is an unexpected token. The expected token is '"' or '''. Line 1, position 62;
  • Expecting an internal subset or the end of the DOCTYPE declaration. Line 5, position 20

当我解决一个错误时,所有这些错误都出现在我身上,另一个错误出现了。

我在问,我是使用完美的方式来加载此文件还是有其他方式?

【问题讨论】:

  • 1.这是什么语言? 2. 可能只是格式错误的 HTML;你需要先在上面运行tidy.sourceforge.net 之类的东西。

标签: .net xml vb.net html-parsing


【解决方案1】:

使用HTML Agility Pack 解析 HTML 文档。

这是一个解析 HTML 文件的 .NET 库。解析器对“真实世界”格式错误的 HTML 非常宽容。对象模型与 System.Xml.XmlDocument 非常相似,但用于 HTML 文档。它支持 XPath 和 XSLT。

Dim htmlDoc As New HtmlDocument()
htmlDoc.Load(Server.MapPath("index.htm"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2017-01-18
    相关资源
    最近更新 更多