현재 XMLUnit으로 작업 중이며 무시할 수있는 방법이 있는지 궁금합니다. id
속성을 비교하고 싶습니다.XMLUnit - 비교에서 'id'속성을 무시합니다.
미리 도움을 주셔서 감사합니다.
현재 XMLUnit으로 작업 중이며 무시할 수있는 방법이 있는지 궁금합니다. id
속성을 비교하고 싶습니다.XMLUnit - 비교에서 'id'속성을 무시합니다.
미리 도움을 주셔서 감사합니다.
이 문제를 해결하기 위해 DifferenceListener을 구현하려고합니다 (this post 참조). 곧 결과를 게시 할 것입니다. 그것은 작동하는 것, 내일 구현을 게시거야.
해결책은 간단합니다. DifferenceEngine
을 구성하여 ATTR_VALUE
차이점을 처리 할 수 있습니다.
class IgnoreIDsDifferenceListener implements DifferenceListener {
private static final int[] IGNORE_VALUES = new int[] {
DifferenceConstants.ATTR_VALUE.getId(),
};
private boolean isIgnoredDifference(Difference difference) {
int differenceId = difference.getId();
for (int i=0; i < IGNORE_VALUES.length; ++i) {
if (differenceId == IGNORE_VALUES[i]) {
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(Node control, Node test) {
}
}
여기에 필요한 것은 속성 이름이 "ID가"여부를 확인하는 것입니다 DifferenceListener를 구현하는 사용자 정의 차이 리스너 클래스를 작성합니다. 표준 Java DOM 기능이 도움이 될 수 있습니다. 하지만 나는 정규 표현식을 통해 이렇게하는 것을 선호한다 :
String controlNode = difference.getControlNodeDetail().getNode().toString();
controlNode .matches("^id=\".*\"")
P.S. 참조 : http://xmlunit.sourceforge.net/api/org/custommonkey/xmlunit/Difference.html
http://stackoverflow.com/questions/1241593/java-how-do-i-ignore-certain-elements-when-comparing-xml 참조하십시오. –