code_junkie

How can I compare 2 XML Documents

Nov 14th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <ids>
  2. <id>1</id>
  3. <id>2</id>
  4. <id>5</id>
  5. <id>6</id>
  6. <id>7</id>
  7. <id>8</id>
  8. <id>9</id>
  9. </ids>
  10. </ids>
  11.  
  12. <ids>
  13. <id>1</id>
  14. <id>2</id>
  15. <id>7</id>
  16. <id>8</id>
  17. <id>9</id>
  18. </ids>
  19.  
  20. XDocument file1Doc = XDocument.Load("File1.xml");
  21. XDocument file2Doc = XDocument.Load("File2.xml");
  22.  
  23. IEnumerable<string> file1Elements = from d in file1Doc.Descendants("Id")
  24. select d.Value;
  25.  
  26. IEnumerable<string> file2Elements = from d in file2Doc.Descendants("Id")
  27. select d.Value;
  28.  
  29. var difference = file1Elements.Except(file2Elements);
  30.  
  31. XDocument file1Doc = XDocument.Load("File1.xml");
  32. XDocument file2Doc = XDocument.Load("File2.xml");
  33.  
  34. IEnumerable<string> file2Elements = from d in file2Doc.Descendants("Id")
  35. select d.Value;
  36.  
  37. var x = from include in file1Doc.Descendants("Id")
  38. where file2Elements.Contains(include.Value) != true
  39. select include;
Add Comment
Please, Sign In to add comment