When I remove a node (with keepGrandChildren) that has both text and child nodes inside, the text is pushed all the way after the child nodes, rather than stay in its original location.
Example:
var doc = new HtmlDocument();
doc.LoadHtml(@"
<span id='first'>
This text comes first.
<span id='second'>This text comes second.</span>
</span>");
var node = doc.GetElementbyId("first");
node.ParentNode.RemoveChild(node, true);
doc.Save(Console.Out);
The output that I get is:
<span id='second'>This text comes second.</span>
this text comes first.
Instead of:
this text comes first.
<span id='second'>This text comes second.</span>
Is there any way of removing a node using keepGrandChildren without the text inside getting pushed towards the end?
I want to conserve absolute order and make sure that no text or nodes change their original position, otherwise the document will be ruined.
Edit:
I’m using HtmlAgilityPack 1.4.6.0 and .NET 4.0
It is a know issue in the HtmlAgilityPack. The following code should solve the problem: