Reputation: 239
I have a situation where two different webservice methods should return exactly the same XML file.
Right now when I get those two responses I compare those XML files using XMLUnit framework which shows xpath location + differences in various nodes like in the following code:
XMLUnit.setIgnoreWhitespace(true);
DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(firstXML,secondXML));
List<Difference> allDiifferences= diff.getAllDifferences();
for(Difference difference : allDiifferences){
System.out.println(difference.getControlNodeDetail().getXpathLocation()+" ("+difference.getControlNodeDetail().getValue()+") /("+difference.getTestNodeDetail().getValue()+")");
}
When I am running the tests in SoapUI I use
log.info
log.error
methods to show the differences which are storred in XMLs.
Is there any better way to show those differences?
Upvotes: 0
Views: 2122
Reputation: 117
I have done some R&D about this and this is what i can tell you, to the best of my knowdledge. XMLUnit offers the most stable and lightweight tools that can effectively find a variety of differences between two xml files. Ofcourse you have the liberty of choosing how to show these differences once they are found.
Upvotes: 3
Reputation: 1765
XMLUnit is good for your use case. or you can try alternative approach of using JAXB to convert XML to Java Objects and then write your custom comparators. (JAXB tools can auto generate classes from your DTDs)
Upvotes: 1