0

I want to modify the DifferenceListener in XMLUnit to ignore the attribute id while comparing XML files. I have tried to do it using the following.

import org.custommonkey.xmlunit.DifferenceListener;
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.DifferenceConstants;

public class ignoreIDs implements DifferenceListener {

    private static final int[] IGNORE_VALUES = new int[] {
        DifferenceConstants.ATTR_VALUE.getId(),
    };

    private boolean isIgnoredDifference(Difference diff) {
        int DiffId = diff.getId();
        for (int value: IGNORE_VALUES) {
            if (DiffId == value) return true;
        }
        return false;
    }

    public int differenceFound(Difference difference) {
        if (isIgnoredDifference(difference)) return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
        else return RETURN_ACCEPT_DIFFERENCE;
    }
    public void skippedComparison() {

    }


}

But I am unable to understand how to enter only the id attribute in the IGNORE_VALUES array. Please help me out.

Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
Debdipta Halder
  • 497
  • 1
  • 5
  • 19
  • 1
    Right now you return true for all differences in attribute values. `diff.getNodeDetail().getNode()` contains the DOM `Attr` objects that correspond to the attributes whose names differ and you must take their local-name or node-name into account. – Stefan Bodewig Oct 08 '15 at 04:50
  • Thanks for the help @stefan. The problem has been solved finally. – Debdipta Halder Oct 08 '15 at 13:17

0 Answers0