开发者

Is there any inbuilt support or native library in the .net for parsing html file?

开发者 https://www.devze.com 2023-01-01 19:38 出处:网络
Why html agility pack is used to parse the information from the html file ? Is not there inbuilt or native library in the .net to parse the information from the html file ? If there then what is the p

Why html agility pack is used to parse the information from the html file ? Is not there inbuilt or native library in the .net to parse the information from the html file ? If there then what is the problem with inbuilt support ? What the benefits of using ht开发者_C百科ml agility pack versus inbuilt support for parsing information from the html file ?


There is no html parser in the BCL, which is why the HTML Agility Pack is recommended by so many.


In one of my applications, I have an HTML template saved in an HTML file. I load it and replace some nodes markers with the values. In this cases I do use .NET XMLDocuments and it works fine. At least in this controlled environment. I don't know what would happen if I tried to parse malformed HTML's.

This is a sample of my code:

Dim S as String = System.IO.File.ReadAllText("Mytemplate.html")

Dim dXML As New System.Xml.XmlDocument
dXML.LoadXml(S)

Dim N As System.Xml.XmlNode
N = dXML.SelectSingleNode("descendant::NodeToFind")

N.InnerText = "Text inside the node"

As I say, this works fine, but if you want to do something more specific to HTML, I guess it would be a good idea to use the HTML agility pack.

0

精彩评论

暂无评论...
验证码 换一张
取 消