Java 使用XML单元比较两个XML对象时无法忽略选定的元素

Java 使用XML单元比较两个XML对象时无法忽略选定的元素,java,xml-parsing,Java,Xml Parsing,在比较两个XML对象时,考虑以下约束: 1) 忽略空白 2) 忽略数组顺序 3) 忽略包含日期的某些元素 请帮助我考虑第三个约束 以下是我尝试的代码: XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreAttributeOrder(true); DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(expectedXML, actualXML));

在比较两个XML对象时,考虑以下约束: 1) 忽略空白 2) 忽略数组顺序 3) 忽略包含日期的某些元素 请帮助我考虑第三个约束 以下是我尝试的代码:

    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);

    DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(expectedXML, actualXML));

    List<?> allDifferences = diff.getAllDifferences();
    if(allDifferences.size() == 0)
        System.out.println("Test Passed");
    else
        System.out.println("Test failed due to following differences: ");
    for(int differences = 0; differences < allDifferences.size(); differences++) {
        System.out.println(allDifferences.get(differences));
XMLUnit.setIgnoreWhitespace(true);
setIgnoreAttributeOrder(true);
DetailedDiff diff=新的DetailedDiff(XMLUnit.compareXML(expectedXML,actualXML));
List allDifferences=diff.getAllDifferences();
if(allDifferences.size()==0)
System.out.println(“测试通过”);
其他的
System.out.println(“由于以下差异,测试失败:”;
for(int differences=0;differences
朋友们,我已按照您的建议编辑了问题。请重新打开问题,让我找到答案。谢谢