Menu

How to ignore element order and decimal differences in XMLUnit2

Help
Reddy
2020-01-30
2020-02-03
  • Reddy

    Reddy - 2020-01-30

    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>

    Also, please help me ignoring  below differences
    

    <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
  • Reddy

    Reddy - 2020-01-31

    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();

     
  • Stefan Bodewig

    Stefan Bodewig - 2020-02-03

    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 Default DifferenceEvaluator so you don't need to implement the special handling Default already contains yourself.

     

Log in to post a comment.

MongoDB Logo MongoDB