将两个 xml 与 XMLUnit2 进行比较时如何忽略具有 It 值的节点

How to ignore nodes with It values when comparing two xmls with XMLUnit2

使用 groovy 与 XMLUnit2 比较 soapui 中的两个 xml 文件,有一些奇怪的情况,两个文件都不同,但可以接受。所以必须ignore/skip那些。

ResXML1:

<alpha:Errors>
    <alpha:Error ShortText="SHiff" Type="11">Generic error occured.</alpha:Error>
    <alpha:Error ShortText="SHiff" Type="12">Generic error occured.</alpha:Error>
</alpha:Errors>
<ShiftAttributes>
    <ShiftAttribute ShiftAttributeCode="41"/>
    <ShiftAttribute ShiftAttributeCode="17"/>
</ShiftAttributes>
<alpha:PriceInfo AgeQualifyingCode="10" Amount="19999.00" DiscountTypes="3" AMZAmount="225.00" NetAmount="19999.00" MCH="1" ValueAddAmount="150.00"/>

ResXML2:

<alpha:Warnings>
    <alpha:Warning ShortText="SHiff" Type="11">Generic error occurred.</alpha:Warning>
</alpha:Warnings>
<ShiftAttributes>
    <ShiftAttribute ShiftAttributeCode="17"/>
    <ShiftAttribute ShiftAttributeCode="41"/>
</ShiftAttributes>
<alpha:PriceInfo AgeQualifyingCode="10" Amount="19999.0" DiscountTypes="3" AMZAmount="225.0" NetAmount="19999.0" MCH="1" ValueAddAmount="150.0"/>

如果有人有任何想法,请在以下条件下帮助我。

1) How to ignore child attribute order? tried different nodematchers(byXpath, byNameandText etc..), but no luck.
<ShiftAttribute ShiftAttributeCode="41"/>
<ShiftAttribute ShiftAttributeCode="17"/>

2) How to ignore decimal value, 100.0 & 100.00. Tried to use BigDecimalElementDifferenceEvaluator, but cannot able to complete in soapui. If we have any easy method please help me?

找到上述问题第一部分的解决方案

差异 = DiffBuilder.compare(ResXML1) .withTest(ResXML2) .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder().whenElementIsNamed("ShiftAttribute").thenUse(ElementSelectors.byNameAndAttributes("ShiftAttributeCode")).elseUse(ElementSelectors.byName).build( ))) .build();