mdarwin
mdarwin

Reputation: 2404

xmlunit sees differences in identical xml

I'm using xmlunit for the first time to compare 2 pieces of xml. It shows great promise but has failed at the first hurdle. It is comparing two almost identical pieces of xml and claims that they are different.

Diff diff = new Diff(control, test);
diff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener()); 

The result returned by xmlunit is as follows:

[different] Expected number of child nodes '3' but was '2' - comparing <SOAP-ENV:Envelope...> at /Envelope[1] to <SOAP-ENV:Envelope...> at /Envelope[1]

But the xml is pretty much the same. Here's the control:

<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope"> <SOAP-ENV:Body> <v:messagegroup xmlns:v="http://www.outfit.net/chargingandpayments/message/1.0"> <v:request> <v:msgcontrol> <v:country>GB</v:country> <v:caller> <v:name>CORE</v:name> <v:signature>Signature</v:signature> <v:version>v10</v:version> </v:caller> <v:headers/> </v:msgcontrol> <v:validate> <v:accountId>MSISDN</v:accountId> </v:validate> </v:request> </v:messagegroup> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

and here's the test String:

<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope"> <SOAP-ENV:Body> <v:messagegroup xmlns:v="http://www.outfit.net/chargingandpayments/message/1.0"> <v:request> <v:msgcontrol> <v:country>GB</v:country> <v:caller> <v:name>CORE</v:name> <v:signature>Signature</v:signature> <v:version>v10</v:version> </v:caller> <v:headers /> </v:msgcontrol> <v:validate> <v:accountId>lblabla</v:accountId> </v:validate> </v:request> </v:messagegroup> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

What am I doing wrong?

Upvotes: 1

Views: 1599

Answers (3)

user4524982
user4524982

Reputation:

The difference is the number of children of SOAP-ENV:Envelope where XMLUnit sees either two or three children. I only see a single "real" child, so the rest likely consists of element content whitespace.

XMLUnit.setIgnoreWhitespace(true);

before evaluating the difference should fix that.

Upvotes: 1

Mouna
Mouna

Reputation: 3359

The value of <v:accountId></v:accountId> is not the same for the two xmls.

First one is <v:accountId>MSISDN</v:accountId> and second one is <v:accountId>lblabla</v:accountId>

Upvotes: 0

JamesB
JamesB

Reputation: 7894

You may need to relax the rules for comparing nodes with XMLUnit:

XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);

Upvotes: 0

Related Questions