Using C# I am trying to pull a section of XML out of the main data source, do work on it and putting it back. I'm doing this for speed reasons, when I do the work while it is still in the main data source it takes ten times as long. But under a certain circumstance the data structure I put back in is not correct. Here is what it's doing:
Say I have a starting XML of:
<Grandparent>
<Parent>
<Child>Kid1</Child>
<Child>Kid2</Child>
<Child>Kid3</Child>
<Child>Kid4</Child>
</Parent>
</Grandparent>
In code I have IXMLDOMNode objects associated with Grandparent and Parent, so I pull out the Parent object to do work on it.
Grandparent.removeChild(Parent);Then I remove the child "Kid2" and when I look at it with the debugger Parent looks like this:
<Parent>
<Child>Kid1</Child>
<Child>Kid3</Child>
<Child>Kid4</Child>
</Parent>
Then I add it back into Grandparent:
Grandparent.appendChild(Parent);And when I look at it XML now it looks like this:
<Grandparent>
<Parent>
<Child>Kid1</Child>
<Child>Kid2</Child>
<Child>Kid3</Child>
</Parent>
<Grandparent>
And when I look at Parent in the debugger it has changed during the append to the new data.
Also, if I do the work without removing Parent first (by commenting out the remove and append lines) it works perfectly.
What is going on here?
BTW-I have tried this with cloning Parent at the top and using replaceChild at the end and I still get the same problem.
Anyone have any suggestions?
Thanks,
-Dan