How do I ignore order of identical elements with XMLUnit's DetailedDifference?

大城市里の小女人 提交于 2019-12-02 02:42:46

RecursiveElementNameAndTextQualifier will yield the same result as the default ElementNameQualifier - b and c are out of order but other than that the documents are identical.

Elements that are out of order constitute a recoverable difference, so Diff and DetailedDiff will say the documents are "similar" but not "identical". So either you ignore recoverable differences or you must override the DifferenceListener rather than the ElementQualifier to downgrade a difference of type CHILD_NODELIST_SEQUENCE_ID from RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR (the default) to RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL. Something like

public int differenceFound(Difference difference) {
    return difference.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID
        ? RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL
        : RETURN_ACCEPT_DIFFERENCE;
}

which accepts the default but downgrades just the out-of-order differences.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!