我在比较 xml 字符串时遇到问题。
我的比较功能是
public static boolean compareXMLs(String xmlSource, String xmlCompareWith){
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setNormalizeWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
Diff myDiff = new Diff(xmlSource, xmlCompareWith);
myDiff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
return myDiff.similar();
}
我的单元测试是
String xml1 = "<a>f</a>";
String xml2 = "<a>1</a>";
assertEquals(true, RestCommonUtility.compareXMLs(xml1, xml2));
xml1 = "<a></a>";
xml2 = "<a>1</a>";
assertEquals(true, RestCommonUtility.compareXMLs(xml1, xml2));
我的单元测试在第一个断言中通过,但在第二个断言中失败。我设置IgnoreTextAndAttributeValuesDifferenceListener
但我的第二个断言仍然失败。有没有办法解决这个问题。?或者是否有任何其他框架可以帮助进行此类比较?