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>

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.