Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Visual Studio unit test to compare two XML files

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).

like image 551
Jon B Avatar asked Mar 25 '23 06:03

Jon B


1 Answers

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#.

like image 183
Artless Avatar answered Apr 05 '23 23:04

Artless