0

我想修改 XMLUnit 中的 DifferenceListener 以在比较 XML 文件时忽略属性 id。我尝试使用以下方法来做到这一点。

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

    }


}

但我无法理解如何在 IGNORE_VALUES 数组中只输入 id 属性。请帮帮我。

4

0 回答 0