4

I need to write a unit test to confirm that when I modify an XML file I get a specific result. I could simply compare the input and output as strings, but I don't want to get failures if little things like white space between elements are different.

Is there a simple way to compare entire XML files in Visual Studio unit tests?

(I'm using 2012 if that matters).

Jon B
  • 51,025
  • 31
  • 133
  • 161

1 Answers1

8

You could try XNode.DeepEquals. Note that for Microsoft's LINQ to XML implementation the element <foo></foo> is not the same as <foo/>.

If you don't mind 3rd party libraries, you have Saxon and Altova XML Tools.

Also, could be relevant: Xml Comparison in C#.

Community
  • 1
  • 1
Artless
  • 4,522
  • 1
  • 25
  • 40