473,471 Members | 4,687 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

AppendChild removes like nodes?

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?
Nov 19 '05 #1
1 1125
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" <be******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
| 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?
|
|
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ray | last post by:
I have put together some pretty simple code for adding and removing elements from an XML file, but am having a problem with toxml writing out the correct format after I have called appendChild on a...
25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
2
by: Chris | last post by:
Hi, I'm having a problem utilizing the DOM. I tried using my own code, but it wasn't working, so I tried to use code straight from another web site and it verified that the problem may not be...
2
by: Michael Lee | last post by:
Does anyone know why the following function works in FireFox but not in IE6? function ShowTable() { clonedNode = document.getElementById("myTable").cloneNode(true); win = window.open();...
2
by: samuel.adam | last post by:
Hi all, I am coding an AJAX DHTML whatever application and I was fed up with always typing a lot of appendChild() functions. I created a custom one called append_children() and wanted to share...
7
by: Robert Oschler | last post by:
I'm having a very painful time converting some Mozilla dynamic DOM code to work with Internet Explore. For example, given this code: -------------- selectBox=document.createElement("SELECT");...
2
by: Marco | last post by:
Hello! Can anyone explain why the following code does not work? (I'm using python2.4.) Cheers, Marco --
3
by: anonymous | last post by:
Can you not append a XmlWhiteSpace node to XmlDocument? See example: using System; using System.Xml; class TestXml { public static void Main(string args)
3
by: TS | last post by:
HI, is there any option while using appendChild so that it doesn't do the autotomatic indentation and line breaks so that the tags are appended back to back? thanks
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.