Uniquely Merging XML files

G

Guest

I was easily able to merge 2 XML files using the guide at
http://support.microsoft.com/kb/311530/EN-US/. However, the two XML files may
contain duplicate tags. Is there an easy way to merge so that I do not have
duplicate tags in the final document? The format of my XML files are as
follows:

<Products>
<Product Name="Some Product">
<Versions>
<Version Value="V02.07.00B ">
<NewFeatures>
<NewFeature id="4324" Value="Added capability to display
thermocouple values in deg C." />
</NewFeatures>
<Fixes>
<Fixed id="4487" Value="Corrected memory issue in transmitting EGD
packets." />
</Fixed>
</Fixes>
</Version>
<Version Value="V02.06.03C ">
<Fixes>
<Fixed id="4505" Value="Corrected problem where I/O packs wouldn't
wait for IP address from DHCP when firmware wasn't loaded." />
</Fixes>
</Version>
</Versions>
</Product>
</Products>

It is an XML file containing release notes. If 2 XML files are merged which
both have a "Fixed" or "NewFeature" tag with the same id and value
attributes, and in the same version and product tag as one in the current
file, then it should not list the tag twice.

The code I'm using is:

XmlTextReader xmlreader1 = new XmlTextReader("1.xml");
XmlTextReader xmlreader2 = new XmlTextReader("2.xml");
DataSet ds = new DataSet();
ds.ReadXml(xmlreader1);
DataSet ds2 = new DataSet();
ds2.ReadXml(xmlreader2);
ds.Merge(ds2, false, MissingSchemaAction.Add);
ds.WriteXml("1-2.xml");
 
N

Nicholas Paldino [.NET/C# MVP]

Ryan,

Unfortunately, there is no easy way to do this. You will have to cycle
through the merged documents and remove the duplicates yourself.

Hope this helps.
 

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

Top