我正在使用 XMLUnit2 来比较 2 个没有相同顺序元素的 XML。我看到以下错误 -
差异 = 预期的子 'billingCode' 但为 'null' - 在 /translateServiceRequestResponse[1]/translateServiceRequestReturn[1]/legacyCode[2]/billingCode[1] 处比较为 NULL
代码
Diff myDiff = DiffBuilder.compare(controlResponse).ignoreWhitespace().ignoreComments().withTest(testResponse).withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).checkForSimilar().build();
System.out.println("Differences = " + myDiff.toString());
控制文件
<translateServiceRequestResponse>
<translateServiceRequestReturn>
<legacyCode>
<amount>0</amount>
<billingCode>VS128</billingCode>
<description>HD Rec</description>
<priceName>EquipChoice X1 HD TP</priceName>
<pricingElementName>X1 HD Receiver</pricingElementName>
<codeAmount>0</codeAmount>
<lobSubType>0</lobSubType>
<addressable>1</addressable>
<nonStandard>false</nonStandard>
</legacyCode>
<legacyCode>
<amount>0</amount>
<billingCode>VF123</billingCode>
<description>HD Rec</description>
<packageCode>VE286</packageCode>
<priceName>EquipChoice X1 HD TP</priceName>
<pricingElementName>X1 HD Receiver</pricingElementName>
<codeAmount>0</codeAmount>
<lobSubType>0</lobSubType>
<addressable>1</addressable>
<nonStandard>false</nonStandard>
</legacyCode>
<legacyCode>
<amount>0</amount>
<billingCode>VF170</billingCode>
<description>HD Rec</description>
<packageCode>VE286</packageCode>
<priceName>EquipChoice X1 HD TP</priceName>
<pricingElementName>X1 HD Receiver</pricingElementName>
<codeAmount>2.5</codeAmount>
<lobSubType>0</lobSubType>
<addressable>1</addressable>
<nonStandard>false</nonStandard>
</legacyCode>
</translateServiceRequestReturn>
测试文件
<translateServiceRequestResponse>
<translateServiceRequestReturn>
<legacyCode>
<amount>0</amount>
<billingCode>VS128</billingCode>
<description>HD Rec</description>
<priceName>EquipChoice X1 HD TP</priceName>
<pricingElementName>X1 HD Receiver</pricingElementName>
<codeAmount>0</codeAmount>
<lobSubType>0</lobSubType>
<addressable>1</addressable>
<nonStandard>false</nonStandard>
</legacyCode>
<legacyCode>
<amount>0</amount>
<billingCode>VF170</billingCode>
<description>HD Rec</description>
<packageCode>VE286</packageCode>
<priceName>EquipChoice X1 HD TP</priceName>
<pricingElementName>X1 HD Receiver</pricingElementName>
<codeAmount>2.5</codeAmount>
<lobSubType>0</lobSubType>
<addressable>1</addressable>
<nonStandard>false</nonStandard>
</legacyCode>
<legacyCode>
<amount>0</amount>
<billingCode>VF123</billingCode>
<description>HD Rec</description>
<packageCode>VE286</packageCode>
<priceName>EquipChoice X1 HD TP</priceName>
<pricingElementName>X1 HD Receiver</pricingElementName>
<codeAmount>0</codeAmount>
<lobSubType>0</lobSubType>
<addressable>1</addressable>
<nonStandard>false</nonStandard>
</legacyCode>
</translateServiceRequestReturn>