Extract differences between two XML files ?

May 21 2013 11:07 AM

i'm implementing a client-server program that synchronize files between computers. At some point, when the client connects to the server, an XML file that contains the directory structure of the location that must be synchronized with the server is sent to the server. If it is not the first time when the client connects, on the server exists such a XML files so there must be found the differences between those 2 files and request from client only the ones that files that have been changed or new. My problem is... how can I find those differences between the XML's. I have 2 XML samples(one XML can have and 1Gb).

First XML (source.xml):

<?xml version='1.0'?>
<RootDirectory name="New folder" dateCreated="5/20/2013 7:16:32 PM">
  <Folder  name="New folder1" >
    <File name="New Text Document11.txt" />
    <File name="New Text Document12.txt"  />
  </Folder>
   <File name="New Text Document1.txt"  />
</RootDirectory>

Second XML (changed.xml):

<?xml version="1.0" encoding="UTF-8"?>
<RootDirectory name="New folder" dateCreated="5/20/2013 7:15:50 PM">
   <Folder name="New folder1">
      <File name="New Text Document11.txt" />
      <File name="New Text Document12.txt" />
   </Folder>
   <Folder name="New folder2">
      <Folder name="New folder21">
         <File name="New Text Document211.txt" />
         <Folder name="New folder211">
            <File name="New Text Document2111.txt" />
            <Folder name="New folder2111">
               <File name="New Text Document21111.txt" />
            </Folder>
         </Folder>
      </Folder>
      <File name="New Text Document21.txt" />
   </Folder>
   <File name="New Text Document1.txt" />
</RootDirectory>

I found an example that uses LinQ to XML http://www.codeproject.com/Articles/45233/Diff-in-XML-files-with-LINQ, but the XML structure used there is different, and it does not help me very much. Given the fact that i can have the tag Folder and File nested inside other nodes..i really don't know how to find the differences ...

Can someone give me an idea?

Thank you!

Best Regards, Oana


Answers (6)