Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any alternatives to XmlUnit?

Tags:

xml

xmlunit

I need to diff large directory structures containing generated .xml and .wsdl files. The generated .xml files differ in the order that child elements appear. The XmlUnit Diff.similar() method is supposed to handle this case:

'Two documents are considered to be "similar" if they contain the same elements and attributes regardless of order.'

This is not the case, however. I took a .xml file, reversed the order of two child elements and XmlUnit says that they are not similar.

XmlUnit is broken, providing no more functionality than the built-in diff utility.

Is there an alternative to XmlUnit that recognizes simple differences in .xml files like ordering of child elements?

like image 990
Dean Schulze Avatar asked Jan 18 '11 17:01

Dean Schulze


2 Answers

I have a similar problem, in my case, I had several tags with the same name, but different attributes (the order didn't matter), but XmlUnit always checked first with first, second with second... that could be swapped. My question was:

Comparing similar xml files with XmlUnit with unordered tags (same tag name with different attributes)

I found a solution here:

http://www.infoq.com/articles/xml-unit-test

In my case, it was solved just overriding the element qualifier:

    Diff diff = new Diff(controlXml, responseXml);
    diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
like image 86
greuze Avatar answered Oct 11 '22 06:10

greuze


I found out that setting the following option resolved the problem of inaccurate (un)similarity:

XMLUnit.setIgnoreWhitespace(true);
like image 26
unludo Avatar answered Oct 11 '22 08:10

unludo