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).
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#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With