0

これを使用して、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 つを解決したときに発生し、別のエラーが表示されます。

このファイルをロードするのに最適な方法を使用していますか、それとも別の方法がありますか?

4

1 に答える 1

6

HTML ドキュメントを解析するには、 HTML Agility Packを使用します。

これは、HTML ファイルを解析する .NET ライブラリです。パーサーは、「実際の」不正な HTML に対して非常に寛容です。オブジェクト モデルは System.Xml.XmlDocument と非常に似ていますが、HTML ドキュメント用です。XPath と XSLT をサポートしています。

Dim htmlDoc As New HtmlDocument()
htmlDoc.Load(Server.MapPath("index.htm"))
于 2010-03-02T14:53:15.440 に答える