Monday, 9 February 2015

C#: compare two xml files



I would like to write a function to compare two XML files. Based on the following cases, the diff could be due to 1.) the order of the nodes and 2.) some nodes or attributes could have been added or removed. I have found a solution to traverse the XML by using a recursive function or LINQ to XML so basically I can get all nodes and attributes. I have read about the XML Diff and Patch Tool but I'm trying to avoid dependencies on my project. An added complexity to this is to determine which line the diff occurred but this is optional for now.


I'm currently thinking of storing the nodes and attributes of the two XML files to a data structure (e.g Dictionary) and compare the Dictionaries later but I'm not pretty sure how to do this one. Can you share some ideas?


No comments:

Post a Comment