For your second problem there is no built-in solution in XMLUnit. For XMLUnit attribute values are strings and as such your attributes are clearly different.
But XMLUnit offers an extension point, you can provide your own custom DifferenceEvaluator that would alter the outcome of ATTR_VALUE differences if they looked like numbers. The example in https://github.com/xmlunit/user-guide/wiki/DifferenceEvaluator shows how to react only to differences on attributes.
The best way to use your own DifferenceEvaluator is to DifferenceEvaluators.chain it after the DefaultDifferenceEvaluator so you don't need to implement the special handling Default already contains yourself.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How to ignore below element order in XMLUnit2, I find something in XMLUnit1, but trying to do in XMLunit2, please let me know if any one have any idea
<shiftattribute shiftattributecode="41">
<shiftattribute shiftattributecode="17">
VS
<shiftattribute shiftattributecode="17">
<shiftattribute shiftattributecode="41"></shiftattribute></shiftattribute></shiftattribute></shiftattribute>
<priceinfo "="" amount="19999.00" discounttypes="3" amzamount="225.00" netamount="19999.00">
VS
<priceinfo "="" amount="19999.0" discounttypes="3" amzamount="225.0" netamount="19999.0"></priceinfo></priceinfo>
Last edit: Reddy 2020-01-30
Found solution for first part of the above question
diff = DiffBuilder.compare(testxml)
.withTest(resxml)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder().whenElementIsNamed("ShiftAttribute").thenUse(ElementSelectors.byNameAndAttributes("ShiftAttributeCode")).elseUse(ElementSelectors.byName).build()))
.build();
For your second problem there is no built-in solution in XMLUnit. For XMLUnit attribute values are strings and as such your attributes are clearly different.
But XMLUnit offers an extension point, you can provide your own custom
DifferenceEvaluatorthat would alter the outcome ofATTR_VALUEdifferences if they looked like numbers. The example in https://github.com/xmlunit/user-guide/wiki/DifferenceEvaluator shows how to react only to differences on attributes.The best way to use your own
DifferenceEvaluatoris toDifferenceEvaluators.chainit after theDefaultDifferenceEvaluatorso you don't need to implement the special handlingDefaultalready contains yourself.