C# HtmlAgilityPack inner html dont change after appending node

c# html html-agility-pack nodes tree

Question

I need to retrieve the loaded html content as plain text in my C# code. However, even when a new node is successfully added to a document's node, the inner HTML of the root node remains unchanged. After debugging, I discovered that the InnerHtml attribute of just the parents of the new node had changed, for instance:

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>

it will be node2.InnerHtml

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

nonetheless root It is InnerHtml.

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

How can I correct this? (I am aware that I could edit each document's node inner HTML by Hand, but Common...)

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

Accepted Answer

I used a way to resolve this problem.WriteContentTo() rather than using qualitiesInnerHtml 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