add and update child nodes in XML
843834May 30 2006 — edited May 31 2006I have a situation where i have 2 xml files. One is the original file and other is the summary of change file. I need to read summary of change file and update original file.
I am having problem when i want to update child nodes. I need to know different ideas to implement it.
Original file
<content>
<a>
<b attr1="one" value="val1">
<c attr="c1" val = "valc">
<d>textd</d>
</c>
<c attr="c2" val = "valc2">
<d>textd1</d>
</c>
</b>
</a>
</content>
My summary of change xml has only lines that need to be changed.
It will start with the parent node of original file.
<content>
<a>
<b attr1="one" value="val1">
<c attr="c1" val = "valc">
<d>newd</d>
</c>
</b>
</a>
</content>
So i have to traverse the second file to know that i have to add a new line <d>newd</d> to the origial document for parent
a>
<b attr1="one" value="val1">
<c attr="c1" val = "valc">
How i will do it? a,b,c tags and properties can be different.
The result should be
<content>
<a>
<b attr1="one" value="val1">
<c attr="c1" val = "valc">
<d>textd</d>
<d>newd</d>
</c>
<c attr="c2" val = "valc2">
<d>textd1</d>
</c>
</b>
</a>
</content>
Please help.