我想修改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属性。请帮帮我。