开发者

HTML Agility pack create new HTMLNode

开发者 https://www.devze.com 2023-02-17 09:06 出处:网络
I\'m using HTML Agility Pack to parse and transform a HTML file, but I get an exception \"Item has already been added\" when try to create a new HTMLNode because of the index parameter.

I'm using HTML Agility Pack to parse and transform a HTML file, but I get an exception "Item has already been added" when try to create a new HTMLNode because of the index parameter.

HtmlNode node1 = new HtmlNode(HtmlNodeType.Element, doc, 0); 
node1.Name = "div"; 

HtmlNode node2 = new HtmlNode(HtmlNodeType.Element, doc, 0); 
node2.Na开发者_C百科me = "div"; 


This is how you can create a node (it basically mimics System.Xml semantics, on purpose):

    HtmlNode div = doc.CreateElement("div");
    myNode.Append(div);

I don't know about this constructor you use, maybe a new one available in version 1.4?

0

精彩评论

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

关注公众号