Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > AppendChild removes like nodes?

Reply
Thread Tools

AppendChild removes like nodes?

 
 
=?Utf-8?B?YmVhbndlZWQ=?=
Guest
Posts: n/a
 
      03-01-2005
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?


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-01-2005
in xml a node can have only one parent, so it can only exist only place in
the document. if you want to copies, you need to clone it (and maybe its
children if desired) and paste the clone.

-- bruce (sqlwork.com)


"beanweed" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| 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?
|
|


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'string'.strip(chars)-like function that removes from the middle? Ethan Furman Python 3 06-17-2008 06:34 PM
Re: 'string'.strip(chars)-like function that removes from the middle? Terry Reedy Python 4 06-17-2008 05:51 PM
Firefox doesn't like appendChild() Christina Javascript 2 11-19-2006 03:50 PM
VS.NET removes "Runat=Server" without asking??? Ronald Colijn ASP .Net 1 11-27-2003 09:01 AM
function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string Beznas ASP General 8 09-10-2003 05:34 PM



Advertisments