Problem with ordering when RemoveChild called

Topics: Developer Forum
Mar 22, 2007 at 12:19 AM
Hi-

I have a structure like this

<levelone>
<leveltwo>
<h1><levelthree></levelthree></h1>
<p><levelthree></levelthree></p>
</leveltwo>
</levelone>

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?

Thanks,

-Mike
Mar 23, 2007 at 6:48 PM
Hi-

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

-Mike