I want to compare two XML files in SoapUI (Groovy) which are similar but the child nodes are not in sequence. I'm using XML unit v2.3.0.
XML1:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
</env:Header>
<soap:Body>
<Details>
<RateType RateTypeID="6">
<RateType>AAAAA</RateType>
<BaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<UOM>percent</UOM>
</RateType>
<RateType RateTypeID="3">
<RateType>BBB</RateType>
<BaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<UOM>percent</UOM>
</RateType>
<RateType RateTypeID="41">
<RateType>CCC</RateType>
<BaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<UOM>percent</UOM>
</RateType>
<RateType RateTypeID="43">
<RateType>DDD</RateType>
<BaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<UOM>percent</UOM>
</RateType>
</Details>
</soap:Body>
</soap:Envelope>
XML2:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
</env:Header>
<soap:Body>
<Details>
<RateType RateTypeID="41">
<RateType>CCC</RateType>
<BaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<UOM>percent</UOM>
</RateType>
<RateType RateTypeID="43">
<RateType>DDD</RateType>
<BaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<UOM>percent</UOM>
</RateType>
<RateType RateTypeID="6">
<RateType>AAAAA</RateType>
<BaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<UOM>percent</UOM>
</RateType>
<RateType RateTypeID="3">
<RateType>BBB</RateType>
<BaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<UOM>percent</UOM>
</RateType>
</Details>
</soap:Body>
</soap:Envelope>
In the above example both the XML's are similar in content but only the sequence differs. I want to compare both of them to know if they are equal.
When I ran the below code:
Diff myDiffSimilar = DiffBuilder.compare(XML1))
.withTest(XML2)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder().whenElementIsNamed("Rate").thenUse(ElementSelectors.selectorForElementNamed("RateValue", ElementSelectors.byNameAndAllAttributes)).build()))
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder().whenElementIsNamed("RateType").thenUse(ElementSelectors.selectorForElementNamed("RateType", ElementSelectors.byNameAndAllAttributes)).build()))
.checkForSimilar().build();
log.info myDiffSimilar.getDifferences().toString();
It gives me the following output
[Expected child '{http://schemas.xmlsoap.org/soap/envelope/}Envelope' but was 'null' - comparing <soap:Envelope...> at /Envelope[1] to <NULL> (DIFFERENT), Expected child 'null' but was '{http://schemas.xmlsoap.org/soap/envelope/}Envelope' - comparing <NULL> to <soap:Envelope...> at /Envelope[1] (DIFFERENT)]
Can someone advice me on the element selector/conditional builder that should be used in this scenario?