aspose file tools*
The moose likes Testing and the fly likes XMLUnit for comparing XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "XMLUnit for comparing XML" Watch "XMLUnit for comparing XML" New topic
Author

XMLUnit for comparing XML

Sneha Teck
Greenhorn

Joined: Mar 20, 2007
Posts: 7
Hi,

Job at hand is to compare 2 XML files.
The result expected is not only an assertion of whether the XMLs are similar or different but also to present the various differences.
This to be done irrespective to the position of the various XML records.

Based on my understanding of XMLUnit, it provides only assertion type results.
has anyone implemented XMLUnit not just as a testing tool but also for purely comparing XML files.

If yes then I would appreciate the help to explore XMLUnit beyond my understanding.

Thanks & Regards,
Sneha.
Sneha Teck
Greenhorn

Joined: Mar 20, 2007
Posts: 7

Example for the XML comparision

-------------
XML-1
-------------
<result>
<item_tuple>
<itemno>1001</itemno>
<desc>Red Bicycle</desc>
</item_tuple>
<item_tuple>
<itemno>1002</itemno>
<desc>Racing Bicycle</desc>
<quantity>5</quantity>
</item_tuple>
<item_tuple>
<itemno>1003</itemno>
<desc>Next Bicycle</desc>
<quantity>5</quantity>
</item_tuple>
</result>

-------------
XML-2
-------------
<result>
<item_tuple>
<itemno>1002</itemno>
<desc>Racing Bicycle</desc>
</item_tuple>
<item_tuple>
<itemno>1006</itemno>
<desc>Learning Bicycle</desc>
</item_tuple>
<item_tuple>
<itemno>1001</itemno>
<desc>Old Bicycle</desc>
</item_tuple>
</result>

Record - 1001 is different , due to the value for node 'desc'
Record 1003 && 1006 to be displayed as not present in the other .
record 1002 differ due to the existence of tag <quantity>


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

Does DetailedDiff not do what you need? In any case, as you point out, this really isn't what XMLUnit is for--have you considered using an XML diff tool? When I search the web I find many.
Sneha Teck
Greenhorn

Joined: Mar 20, 2007
Posts: 7
David,

Thank You for your input.
The need is to explore the XMLUnit. Hence no diff tools.
praneel shah
Greenhorn

Joined: Mar 16, 2010
Posts: 17
use beyond compare software, it will give you all the differnces and many other functioalities...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: XMLUnit for comparing XML