我第一次使用 xmlunit 来比较 2 条 xml。它显示出巨大的希望,但在第一个障碍中失败了。它正在比较两个几乎相同的 xml,并声称它们是不同的。
Diff diff = new Diff(control, test);
diff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
xmlunit返回的结果如下:
[different] Expected number of child nodes '3' but was '2' - comparing <SOAP-ENV:Envelope...> at /Envelope[1] to <SOAP-ENV:Envelope...> at /Envelope[1]
但是xml几乎是一样的。这是控制:
<?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>
这是测试字符串:
<?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>
我究竟做错了什么?