Problem with ordering when RemoveChild called

Topics: Developer Forum
Mar 21, 2007 at 11:19 PM

I have a structure like this


And I'm parsing it like this:

HtmlNodeCollection nodes = _htmlDocument.DocumentNode.SelectNodes("//*");

foreach (HtmlNode node in nodes)
HtmlNode parentnode = node.ParentNode;
HtmlTextNode textnode1 = node.OwnerDocument.CreateTextNode("START");
parentnode.InsertBefore(textnode1, node);

HtmlTextNode textnode2 = node.OwnerDocument.CreateTextNode("END");
parentnode.InsertAfter(textnode2, node);

parentnode.RemoveChild(node, true);


The problem is that if I call RemoveChild, it reorders the two lines in the leveltwo innerhtml. If I don't call removechild, it keeps them in the correct order.

Could this be a bug? If so, is there a workaround for it?


Mar 23, 2007 at 5:48 PM

I think I found the problem and a fix for this---I'll post this to the "issues" secton under item 9113.