Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to compare 2 XML documents in .NET [duplicate]

Tags:

.net

xml

I have a heap of unit tests that need to check XML outputs.

I have started out comparing strings but this isn't going to scale as formatting and superficial differences get in the way.

What is the easiest way in .NET to evaluate whether the generated XML is semantically the same as what the test expects?

Closed as duplicate of How would you compare two XML Documents?

like image 617
Brownie Avatar asked Nov 09 '08 11:11

Brownie


People also ask

How do I compare two XML files in Visual Studio?

Steps to compare contents of two files Open both the files in VS Code. From the left Explorer panel, right-click the first file and choose Select for Compare from the right-click menu. Then right-click the second file and choose Compare with Selected.


1 Answers

Microsoft offers its XML Diff tools/classes here. I haven't personally used it, but it sounds like it'll get you started:

"By using the XMLDiff class, the programmer is able to determine if the two files are in fact different based on the conditions that are important to their application"

It seems to cope with different ordering, spacing, namespace prefixes etc.

like image 108
Xiaofu Avatar answered Oct 12 '22 22:10

Xiaofu