I have frequent need to test that XML files are correct and need a way of testing that 2 XML strings (or documents) are identical, such as:
XMLAssert.assertEquals(String xmlExpected, String xmlActual);
In addition it would be useful to show where the xml documents differed.
This should be restricted to documents with standalone="yes" (i.e. the DTD or schema - if any - is not significant). This means that there are no default values, and attribute types are irrelevant. Adjacent text PCDATA nodes should be normalised (concatenated).
Note that this cannot be done simply by lexical comparison
Assert.assertEquals(xmlExpected, xmlActual);
as there are indefinitely many ways of rendering the same XML infoset. The comparison should take account of namespaces on elements and attributes (but not attribute values - which are not part of the spec).
One way to do this might involve canonicalising both documents. Alternatively an XMLDiff could be used.
I could not find anything so wrote my own a few years ago.
[I also have a particular need to compare floating point values though this must be a hack since the data type of CDATA or PCDATA can only be guessed and is out of immediate scope for the question.]
NOTE: There will probably need to be a specific solution for each language. I am particularly interested in Java and C#