How to merge two different child nodes in the same XML file

Posted by user814698 on Stack Overflow See other posts from Stack Overflow or by user814698
Published on 2011-06-29T14:31:15Z Indexed on 2011/06/29 16:22 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

I have an XML file and I would like to merge two different CONTACT child nodes.

I have checked these websites it shows how to merge two different xml files into a single file.

http://www2.informatik.hu-berlin.de/~obecker/XSLT/#merge

Merge XML documents

In my case this is my first contact in the xml file:

<CONTACT>
<PDE-Identity>N65539</PDE-Identity>
<FirstName>Arun_niit</FirstName>
<LastName>Arun_niit</LastName>
<Facebook-ID/>
<EMAILS>
<EMail>
<Type>yahoo</Type>
<Value>[email protected]</Value>
</EMail>
</EMAILS>
</CONTACT>

This is the second contact in the file:

<PDE-Identity>N65567</PDE-Identity>
<FirstName>Arun_niit</FirstName>
<LastName>Ramanathan</LastName>
<Facebook-ID/>
<EMAILS>
<EMail>
<Type>gmail</Type>
<Value>[email protected]</Value>
</EMail>
<EMail>
<Type>yahoo</Type>
<Value>[email protected]</Value>
</EMail>
</EMAILS>
</CONTACT>
<CONTACT>

I know both of the contacts are belongs to the same person. How can i merge these two contacts in the same xml file.

Original XML File:

 <?xml version="1.0" encoding="UTF-8"?>
<CONTACTS>

<CONTACT>
<PDE-Identity>N65539</PDE-Identity>
<FirstName>Arun_niit</FirstName>
<LastName>Arun_niit</LastName>
<Facebook-ID/>
<EMAILS>
<EMail>
<Type>yahoo</Type>
<Value>[email protected]</Value>
</EMail>
</EMAILS>
</CONTACT>

<CONTACT>   
<PDE-Identity>N65567</PDE-Identity>
<FirstName>Arun_niit</FirstName>
<LastName>Ramanathan</LastName>
<Facebook-ID/>
<EMAILS>
<EMail>
<Type>gmail</Type>
<Value>[email protected]</Value>
</EMail>
<EMail>
<Type>yahoo</Type>
<Value>[email protected]</Value>
</EMail>
</EMAILS>
</CONTACT>


<CONTACT>
<PDE-Identity>N65567</PDE-Identity>
<FirstName>Rangarajkarthik</FirstName>
<LastName>karthik Rangaraj</LastName>
<Facebook-ID/>
<EMAILS>
<EMail>
<Type>gmail</Type>
<Value>[email protected]</Value>
</EMail>
<EMail>
<Type>yahoo</Type>
<Value>[email protected]</Value>
</EMail>
</EMAILS>
</CONTACT>

<CONTACTS>

© Stack Overflow or respective owner

Related posts about Xml

Related posts about merge