How to insert a new node at a specific position

E

eva.mukhija

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>
 
M

Martin Honnen

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.
 
E

eva.mukhija

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top