Finding the difference between two XML files
I have built two XML files that map the content of a given folder:
<root>
<folder name="C:\a\b" permision="yes" folderCount="1">
<folders>
<folder name="C:\a\b\c" permision="yes" folderCount="1">
<folders>
<folder name="C:\a\b\c\e" permision="yes" folderCount="0">
<folders/>
<files>
<file name="401-1.htm"/>
<file name="401-2.htm"/>
<file name="401-3.htm"/>
</files>
</folder>
<folder name="C:\a\b\d" permi开发者_如何学运维sion="yes" folderCount="0">
<folders/>
<files>
<file name="401-4.htm"/>
<file name="401-5.htm"/>
<file name="401-3.htm"/>
</files>
</folder>
</folders>
<files/>
</folder>
</root>
I'd like to know if there is a way to find the difference between the files.
(One file is the old state and the second is the new state, and it's only possible to add files and not remove them. It would be great to remove identical nodes from the new state so only the new files will be left).
I would use LINQ to XML like the project below:
Diff in XML files with LINQ:
http://www.codeproject.com/KB/linq/LinqDiff.aspx
If you'd like to do it in code, you could use Microsoft'ss XML Diff and Patch GUI Tool, and although there isn't a great deal of documentation, there is enough that you should be able to easily diff two XML files in code, in a fairly short space of time. I use it in a couple of projects as part of a series of unit tests which ensure that XML files are being generated correctly.
If you just want to view the differences between the two files, then you could just use any decent diff tool.
精彩评论