HtmlAgilityPack replace node

前端 未结 2 512
星月不相逢
星月不相逢 2020-12-14 08:04

I want to replace a node with a new node. How can I get the exact position of the node and do a complete replace?

I\'ve tried the following, but I can\'t figured out

2条回答
  •  误落风尘
    2020-12-14 08:47

    Have Implemented the following solution to achieve the same.

    var htmlStr = "bold_one
    strong
    bold_two"; var htmlDoc = new HtmlDocument(); HtmlDocument document = new HtmlDocument(); document.Load(htmlStr); htmlDoc.DocumentNode.SelectSingleNode("//div[@class='olddiv']").Remove(); htmlDoc.DocumentNode.SelectSingleNode("//div[@class='LatestLayout']").PrependChild(newChild) htmlDoc.Save(FilePath); // FilePath .html file with full path if need to save file.

    so selecting an object and removing respective HTML object

    and appending it as chile. of respective object.

提交回复
热议问题