C# HtmlAgilityPack inner html dont change after appending node

c# html html-agility-pack nodes tree

Question

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... )

1
5
10/5/2015 9:16:23 AM

Accepted Answer

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

4
12/5/2013 4:50:32 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow