Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# HtmlAgilityPack inner html dont change after appending node

In my C# i change loaded html, and need to get html document as plain text. But whenever i append new node to one of document's node, the inner html of root node doesn't change, even if the new node is successfully added. After debugging i noticed that only the parents of new node has the change in their InnerHtml property, for example:

HtmlDocument doc;
HtmlNode root doc.DocumentNode;
HtmlNode node2 = root.ChildNodes[1];
HtmlNode newNode = new HtmlNode(...);
node2.Append(newNode);

Having:

<root>
    <node1>
    </node1>
    <node2>
        <node3>
        <node3>
        <newNode>
        </newNode>
    </node2>
</root>

node2.InnerHtml will be

        <node3>
        <node3>
        <newNode>
        </newNode>

but root.InnerHtml is

<root>
    <node1>
    </node1>
    <node2>
        <node3>
        <node3>
    </node2>
</root>

How can i fix this right? ( i know i could manually update every document's node inner html, but common... )

like image 742
Ben Avatar asked Oct 03 '22 06:10

Ben


1 Answers

I have solved this issue by using method WriteContentTo() instead of using properties InnerHtml or OuterHtml

like image 119
Ben Avatar answered Oct 16 '22 18:10

Ben