471,357 Members | 1,077 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 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 2109


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Hans-Michael Rupp | last post: by
1 post views Thread by Rafaela K. Azinhal | last post: by
3 posts views Thread by Andrew Clark | last post: by
4 posts views Thread by neilcancer | last post: by
6 posts views Thread by gk | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.