473,508 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to insert a new node at a specific position

I'm using DOM Parser for manipulating XML Document.I need to detect the
end of a particular node in an XML document and insert an entirely new
node just before its end as depicted below
The XML Document can contain multiple occurances of type Node1:
I need to add a new child node(newNode) just before it ends. Can any
one help??
<Node1>

<newNode></newNode>
</Node1>
<Node1>
<newNode></newNode>
</Node1>
<Node1>
<newNode></newNode>
</Node1>

Aug 11 '05 #1
4 2163


ev*********@gmail.com wrote:
I'm using DOM Parser for manipulating XML Document.I need to detect the
end of a particular node in an XML document and insert an entirely new
node just before its end as depicted below
The XML Document can contain multiple occurances of type Node1:
I need to add a new child node(newNode) just before it ends. Can any
one help??
<Node1>

<newNode></newNode>
</Node1>
<Node1>
<newNode></newNode>
</Node1>
<Node1>
<newNode></newNode>
</Node1>


You can find all <Node1> elements using
xmlDocument.getElementsByTagName("Node1")
which gives a collection you can loop through, for each node in the
collection you can then call the appendChild method to append a newly
created node.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 11 '05 #2
What if Node1 contains many child nodes and I intend to append this in
the last.. Will the above suffice??
<Node1>
<A></A>
<B></B>
<newNode></newNode>
</Node1>

Aug 11 '05 #3


ev*********@gmail.com wrote:
What if Node1 contains many child nodes and I intend to append this in
the last.. Will the above suffice??


The appendChild method appends the node passed in as the last child the
method is called on, yes. See the DOM documentation
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247>
it documents methods like appendChild.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 11 '05 #4
Thanks Martin..:)

Aug 12 '05 #5

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

Similar topics

2
3484
by: Hans-Michael Rupp | last post by:
Hallo! How can find out the postion of a node with a particular content in the nodeset WITHOUT being in the context? I would like have something like <xsl:variable name="position"...
1
2575
by: Rafaela K. Azinhal | last post by:
Please, help me with following code snippet ' Load xml document Dim xmlDoc As New XmlDocument() xmlDoc.Load(http://localhost/VT/reports/VT_actual_owsPivotTable.xml) ' define namespacemanager...
4
12387
by: mike | last post by:
Hello. Let's say I have the following XML document: <ROOT><Element1>Some Text</Element1></ROOT> I want to add a new element after Element1. I tried the following but, naturally, it doesn't...
3
22064
by: Andrew Clark | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** it's been a while since i have poseted to this newsgroup, but for a long time i was not programming at all. but now that i am out of...
4
5017
by: neilcancer | last post by:
i wrote a function to insert an elem into a list, but it was wrong,wrong,wrong! and i have no idea about why it was wrong. If anyone know, leave your advice, thank you. #include<stdio.h>...
9
7813
by: raylopez99 | last post by:
What's the best way of implementing a multi-node tree in C++? What I'm trying to do is traverse a tree of possible chess moves given an intial position (at the root of the tree). Since every...
6
2845
by: gk | last post by:
Hi, I have trouble figuring out how to search for a particular string in an XML document and annotating it. For example if I'm looking for the string "sentence with tagged words" and wish to...
10
10477
by: Aditya | last post by:
Hi All, I would like to know how it is possible to insert a node in a linked list without using a temp_pointer. If the element is the first element then there is no problem but if it is in...
0
1289
by: monkeyboysdad | last post by:
I have an xml document - <?xml version="1.0"?> <mstns> <curves id="curve0"> </curves> <classification name="ROUND STN STL BAR"> <material name="DIA 3MM STN STL 316 h9"> ...
0
7124
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
7326
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,...
0
7385
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...
0
7498
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...
0
5629
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,...
0
4707
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...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
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
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.