问题
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:
I have solved this issue by using method WriteContentTo()
instead of using properties InnerHtml
or OuterHtml
来源:https://stackoverflow.com/questions/20390901/c-sharp-htmlagilitypack-inner-html-dont-change-after-appending-node