472,784 Members | 1,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

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 2141


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
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
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
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
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
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
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
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
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
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.