简体   繁体   中英

How to wisely compare two XML files in SoapUI?

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?

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM