HTML Agility Pack - ReplaceNode doesn't change the InnerHTML of the Body

Posted by morsanu on Stack Overflow See other posts from Stack Overflow or by morsanu
Published on 2010-04-07T08:55:21Z Indexed on 2010/04/08 20:43 UTC
Read the original article Hit count: 1398

Hi there,

I have this

The body:

<body><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent leo leo, ultrices eu venenatis et, rutrum fringilla dolor.</p></body>

The code:

HtmlNode body = doc.DocumentNode.SelectSingleNode("//body");

Dictionary<HtmlNode, HtmlNode> toReplace = new Dictionary<HtmlNode, HtmlNode>();

// I do some logic here adding nodes to the toReplace dictionary.

foreach (HtmlNode replaceNode in toReplace.Keys)
{
    replaceNode.ParentNod.ReplaceChild(toReplace[replaceNode], replaceNode);
}

After i do this, the InnerHtml of the body node remains the same as from beginning, although the OutterHtml or the InnerText are showing the good result. Is there something wrong with my code?

The result:

// body.InnerHtml
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent leo leo, ultrices eu venenatis et, rutrum fringilla dolor.</p>

// body.OutterHtml
<body><p>Lorem ipsum dolor sit amet...</p></body>

© Stack Overflow or respective owner

Related posts about htmlagilitypack

Related posts about innerhtml