473,883 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
+ 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.A ppendChild(selp arentnode)

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 1141
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******@discu ssions.microsof t.com> wrote in message
news:6B******** *************** ***********@mic rosoft.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.A ppendChild(selp arentnode)
|
| 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
3586
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 node. Here is a snippet: if (action == 'add'): newCluster = domi.createElement(elementType) newCluster.setAttribute("Name", elementName) elem.appendChild(newCluster)
25
5215
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 calculate the totals in each row. when i try however, i receive the error: "Error: 'elements' is null or not an object"
2
22239
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 mine. I am using IE 6.0.28 (sp5) on a Windows 2000 Server. I am very new to DOM so I'm not ruling out that I'm doing something wrong. However, I am posting the code that I got from another site because I did notice that the examples were using...
2
8524
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(); win.document.body.appendChild(clonedNode); } I am trying to display a table with id="myTable" in a new window. IE6
2
10857
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 it if anyone need such a function. function append_children() { var a = append_children.arguments;
7
3151
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"); selectBox.name="theSelectBox"; optionOne=document.createElement("OPTION"); optionOne.name="option1"; optionOne.value="one";
2
3449
by: Marco | last post by:
Hello! Can anyone explain why the following code does not work? (I'm using python2.4.) Cheers, Marco --
3
2311
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
5468
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
9942
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9792
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10847
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10416
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9574
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7129
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5991
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4220
muto222
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.