0

I need to compare 2 xml files and write the difference(newly added rows) in third xml file. The xml files has the result of a query. I found many third party tools but those are not specific for this condition. Any suggestions will he helpful.

xml1

<root>
<rdm>
<Model> aa</model>
</rdm>
<rdm>
<Model> bb </Model>
</rdm>
</root>

xml2

<root>
<rdm>
<Model> aa</model>
</rdm>
<rdm>
<Model> bb </Model>
</rdm>
<rdm>
<Model>cc</Model>
</rdm>
</root>

 The xml3 should look like 
<root>
<rdm>
<Model>cc</Model>
</rdm>
</root>
Aswini
  • 51
  • 4
  • 16

2 Answers2

0

You could load your xml into two datasets, merge them and consider the new elements as the difference between them.

https://msdn.microsoft.com/en-us/library/aa984388(v=vs.71).aspx

http://www.codeproject.com/Articles/30102/Comparing-DataSets-using-LINQ

Oscar
  • 13,594
  • 8
  • 47
  • 75
  • GetChanges() does not return newly added rows. It is returning the original data in 1st dataset. and merge has duplicates in it which I don't want. – Aswini Mar 09 '15 at 09:08
0

You can implement your own comparer by converting your XML files to objects using XmlDocument or XDocument. You can then compare two objects using IEquatable.Equals(). See this answer C# XML Diffing algorithm

Community
  • 1
  • 1
jmc
  • 1,649
  • 6
  • 26
  • 47