Connecting Tech Pros Worldwide Help | Site Map

merge two xml file of the same structure

Newbie
 
Join Date: Oct 2008
Posts: 11
#1: Oct 28 '08
I have two xml files with the same structure
file1
<Topic>
<Child>
<wpf>
<Child>
<learn>
<Child>
</Child>
<Link>
<url>http://1.com</url>
</Link>
</learn>

<animation>
<Child>
</Child>
<Link>
<url>www.2.com</url>
</Link>
</animation>
</Child>
<Link>
<url>www.1up.com</url>
<url>www.2up.com</url>
</Link>
</wpf>
<csharp>
<Child></Child>
<Link></Link>
</csharp>
</Child>
<Link>
</Link>
</Topic>

File 2
<Topic>
<Child>
<wpf>
<Child>
<learn>
<Child>
</Child>
<Link>
<url>http://windowsclient.net/learn/video.aspx?v=55062</url>
</Link>
</learn>
</Child>
<Link>
</Link>
</wpf>
</Child>
<Link>
</Link>
</Topic>

How do i merge the two files so that the learn part looks like this

<learn>
<Child>
</Child>
<Link>
<url>http://1.com</url>
<url>http://windowsclient.net/learn/video.aspx?v=55062</url>
</Link>
</learn>
Member
 
Join Date: Oct 2008
Posts: 50
#2: Oct 28 '08

re: merge two xml file of the same structure


Doesn't look like the same structure to me. In the first file you have some different tags
Newbie
 
Join Date: Oct 2008
Posts: 11
#3: Oct 28 '08

re: merge two xml file of the same structure


File 1
<Contents version="0.8">
<Tag name="WPF">
<Children>
<Tag name="Visual Basic">
<Children></Children>
<Links>
<link source="http://www.yahoo.com" title="YAHOO"></link>
<link source="http://www.google.com" title="GOOGLE"></link>
<link source="http://www.live.com" title="LIVE"></link>
<link source="http://www.hello.com" title="Hello"></link>
</Links>
</Tag>
</Children>

<Links>
<link source="http://www.yahoo.com" title="YAHOO"></link>
<link source="http://www.google.com" title="GOOGLE"></link>
<link source="http://www.live.com" title="LIVE"></link>
</Links>
</Tag>
</Contents>

file 2
<Contents version="0.8">
<Tag name="WPF">
<Children>
<Tag name="Visual Basic">
<Children></Children>
<Links>
<link source="http://www.abc.com" title="YAHOO"></link>
<link source="http://www.google.com" title="GOOGLE"></link>
<link source="http://www.live.com" title="LIVE"></link>
<link source="http://www.hello.com" title="Hello"></link>
</Links>
</Tag>
<Tag name="C#">
<Children></Children>
<Links>
<link source="http://www.yahoo.com" title="YAHOO"></link>
<link source="http://www.google.com" title="GOOGLE"></link>
<link source="http://www.live.com" title="LIVE"></link>
</Links>
</Tag>
</Children>

<Links>
<link source="http://www.yahoo.com" title="YAHOO"></link>
<link source="http://www.google.com" title="GOOGLE"></link>
<link source="http://www.live.com" title="LIVE"></link>
</Links>
</Tag>
</Contents>
i would want the result to be something like this
<Tag name="Visual Basic">
<Children></Children>
<Links>
<link source="http://www.yahoo.com" title="YAHOO"></link>
<link source="http://www.google.com" title="GOOGLE"></link>
<link source="http://www.live.com" title="LIVE"></link>
<link source="http://www.hello.com" title="Hello"></link>
<link source="http://www.abc.com" title="YAHOO"></link>

</Links>
</Tag>
Reply