Xml comparison code in .Net
Hi my project required me to compare two xml files, which are having same format but different data.
Show those differences and merge the files to produce a new file.
Is there any way to do this using c#?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
naura paxRank #2,843 · 502 reputationPosted Nov 4, 2009, 10:54 PM EST
which version are you using? if it is 3.5 you can use LINQ to xml to query data from one xml and write it into another
while there is a document way of doing it with datasets in this link:
http://support.microsoft.com/kb/311530
while this is one straight copy node to node just read the answer in the given post:
http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=28347
Vinaya5 reputationPosted Nov 5, 2009, 8:03 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Nov 6, 2009, 10:39 AM EST
You can read the XML data into collections using the XmlSerializer Class, then sort it if necessary, then write a simple compare. Assuming there is not other data to be written, the merged data could be written using the XmlSerializer Class.