Proper way to change HtmlNode value in document using HtmlAgilityPack

c# html html-agility-pack parsing xpath

Question

I want to change node's inner html in the document but the following code doesn't work unfortunately:

HtmlNodeCollection sourceTables = _sourceDoc.DocumentNode.SelectNodes("//table");
sourceTables[0].InnerHtml = "lalala";

The node's inner html changes properly, but it doesn't affect document html.

And this method doesn't work, because the node cannot be found:

_sourceDoc.DocumentNode.ReplaceChild(HtmlNode.CreateNode("<test></test>"), sourceTables[0]);

Accepted Answer

This was a notable bug in the library (http://htmlagilitypack.codeplex.com/workitem/32959). It has been fixed very recently, at least in the source (it's not in the 1.4.6 release). You can do a get latest and recompile.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why