-2

I'm working on a sync program in C# that should be able to sync folders and file between a server and multiple clients. The problem is that only what is on the server should be sent to the clients. I want to compare two XML files and get the result in a new XML file. I want to be able to see what is the differences between file 1 and 2 and only get what file 2 is missing from file 1. Something like shown below. XML file 1 - XML file 2 = XML file 3

XML file 1 - This is a view of all the files and sub-folders

<Sync>
  <file name="file1.exe" md5="301977135631682077322272102379711510898" />
  <file name="file2.gif" md5="198293138141481761522471841122211715365100" />
  <file name="file3.docx" md5="2421394619714515234127212777726185214112245"/>
  <file name="file4.docx" md5="192234220151104120192442391857158145211131" />
  <file name="file5.txt" md5="168303710116177182411519715713816617416674" />
  <file name="file6.bmp" md5="1792011292231121792151655125106213101156216" />
  <file name="file7.txt" md5="33187821621591371126952143181189193108" />
  <file name="file8.ini" md5="2282341791393124126722550279185251209139" />
  <folder name="folder1">
    <file name="file9.reg" md5="17553712523921412874140137119129165185219" />
    <folder name="folder2">
      <file name="file10.png" md5="13197182105223023710241762821170145139202" />
      <file name="file11.docx" md5="205130242851746130180151132127731757621530" />
    </folder>
  </folder>
</Sync>

XML file 2 - This is a view of all another path of files and sub-folders

<Sync>
  <file name="file1.exe" md5="301977135631682077322272102379711510898" />
  <file name="file7.txt" md5="33187821621591371126952143181189193108" />
  <file name="file8.ini" md5="2282341791393124126722550279185251209139" />
  <folder name="folder1">
    <file name="file9.reg" md5="17553712523921412874140137119129165185219" />
      <file name="file13.docx" md5="205130242851746130180151132127731757621530" />
    <folder name="folder2">
      <file name="file11.docx" md5="205130242851746130180151132127731757621530" />
      <file name="file12.docx" md5="205130242851746130180151132127731757621530" />
    </folder>
  </folder>
</Sync>

XML file 3 - This is a view of all the files and sub-folders file 1 is missing

<Sync>
  <file name="file2.gif" md5="198293138141481761522471841122211715365100" />
  <file name="file3.docx" md5="2421394619714515234127212777726185214112245"/>
  <file name="file4.docx" md5="192234220151104120192442391857158145211131" />
  <file name="file5.txt" md5="168303710116177182411519715713816617416674" />
  <file name="file6.bmp" md5="1792011292231121792151655125106213101156216" />
  <folder name="folder1">
    <folder name="folder2">
      <file name="file10.png" md5="13197182105223023710241762821170145139202" />
    </folder>
  </folder>
</Sync>
Pino
  • 31
  • 1
  • 5
  • what is your question? https://stackoverflow.com/help/how-to-ask – hiro protagonist Aug 23 '15 at 16:27
  • Buy a copy of Beyond Compare 4. – Tobias Knauss Aug 23 '15 at 16:29
  • Thanks for letting us know what you are working on. We're right here when you get stuck and want to post some code that you need help with. – SQLMason Aug 23 '15 at 16:35
  • just flatten ur structure and store the file path with the filename....so easy that way – Brandon Seydel Aug 23 '15 at 16:57
  • Use Left Outer Join Linq Method : https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b – jdweng Aug 23 '15 at 17:07
  • @Dan Andrews, hiroprotagonist, Tobias Knauss - if you think this question is duplicate of another question, just mark it as duplicate. Online rant has even less value than duplicate question. – vittore Aug 23 '15 at 17:53
  • possible duplicate of [Compare XML fragments & return differences](http://stackoverflow.com/questions/10482514/compare-xml-fragments-return-differences) – vittore Aug 23 '15 at 17:54
  • @vittore Did I say something that led you to believe that I thought this question was a duplicate or are you just trying to be efficient by sending a rant to all of us in one comment? I thanked the op for telling us what he's working on - which is intent of his post (does it read differently to you?). I also let him know that should he have a problem, we're anxiously waiting to hear it. Is it stands, there is no question mark in the post. – SQLMason Aug 24 '15 at 01:44

2 Answers2

0

you can use WinMerge who is an Open Source differencing and merging tool for Windows. he can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.

BELotfi
  • 51
  • 1
  • 3
-1

The easiest way of doing this is by using diffgrams

Here is example Compare XML fragments & return differences

Key code:

var result = new XDocument();
var writer = result.CreateWriter();

var diff = new Microsoft.XmlDiffPatch.XmlDiff();    
diff.Compare(node1, node2, writer);

writer.Flush(); 
writer.Close();
Community
  • 1
  • 1
vittore
  • 17,449
  • 6
  • 44
  • 82