G
Guest
This is a problem with a ASP.NET application I am writing.
The interface allows a user to manipulate an XML document.
I have in my xmldocument
.. . .
<item id="1">
<parents />
<label>item1</label>
</item>
<item id="3">
<parents>
<parent>1</parent>
</parents>
<label>item3</label>
</item>
<item id="2">
<parents />
<label>item2</label>
</item>
.. . .
In short, item3 is a "child" of item1 but item2 is a "peer".
Code to allow a user to cut and paste items tries to read the
parent information from the item being pasted to, and then
add that information to the item being pasted.
For example if I wanted to cut out item2 and paste it in as
a "child" of item3 I should get
.. . .
<item id="1">
<parents />
<label>item1</label>
</item>
<item id="3">
<parents>
<parent>1</parent>
</parents>
<label>item3</label>
</item>
<item id="2">
<parents>
<parent>1</parent>
<parent>3</parent>
</parents>
<label>item2</label>
</item>
.. . .
(i.e. item2 is now a "child" of item3 which is also a "child" of item1),
but what I get is
.. . .
<item id="1">
<parents />
<label>item1</label>
</item>
<item id="3">
<parents/>
<label>item3</label>
</item>
<item id="2">
<parents>
<parent>1</parent>
<parent>3</parent>
</parents>
<label>item2</label>
</item>
.. . .
By writing choice lines to a text file I find that the problem lies
in this line of code
cutparentnode.AppendChild(selparentnode)
Apparently, when I append the element <parent>1</parent> to item2
it removes that same element from item3. I see the documetation
says "If the newChild is already in the tree, it is first removed."
I thought it meant if the newchild is in the tree of the node being
appended and its children. But I guess it means in the tree of the
document?
Whatever. How do I append an element to a node without having the
same element removed elsewhere in the document?
The interface allows a user to manipulate an XML document.
I have in my xmldocument
.. . .
<item id="1">
<parents />
<label>item1</label>
</item>
<item id="3">
<parents>
<parent>1</parent>
</parents>
<label>item3</label>
</item>
<item id="2">
<parents />
<label>item2</label>
</item>
.. . .
In short, item3 is a "child" of item1 but item2 is a "peer".
Code to allow a user to cut and paste items tries to read the
parent information from the item being pasted to, and then
add that information to the item being pasted.
For example if I wanted to cut out item2 and paste it in as
a "child" of item3 I should get
.. . .
<item id="1">
<parents />
<label>item1</label>
</item>
<item id="3">
<parents>
<parent>1</parent>
</parents>
<label>item3</label>
</item>
<item id="2">
<parents>
<parent>1</parent>
<parent>3</parent>
</parents>
<label>item2</label>
</item>
.. . .
(i.e. item2 is now a "child" of item3 which is also a "child" of item1),
but what I get is
.. . .
<item id="1">
<parents />
<label>item1</label>
</item>
<item id="3">
<parents/>
<label>item3</label>
</item>
<item id="2">
<parents>
<parent>1</parent>
<parent>3</parent>
</parents>
<label>item2</label>
</item>
.. . .
By writing choice lines to a text file I find that the problem lies
in this line of code
cutparentnode.AppendChild(selparentnode)
Apparently, when I append the element <parent>1</parent> to item2
it removes that same element from item3. I see the documetation
says "If the newChild is already in the tree, it is first removed."
I thought it meant if the newchild is in the tree of the node being
appended and its children. But I guess it means in the tree of the
document?
Whatever. How do I append an element to a node without having the
same element removed elsewhere in the document?