XMLunit Comparison failure because child nodes order

醉酒当歌 提交于 2020-01-05 12:32:35

问题


I'm comparing a generated XML file with another example using XMLunit, and Im having problems with ChildNodes Order and their attributes. (Linux and Mac generation differ)

This is what I've tried:

@Test
public void testComparingXML() throws Exception {
    XMLUnit.setIgnoreWhitespace(true);
    String expectedXml = IOUtils.toString(ConnectorStrategyStudioXmlTest.class.getClassLoader().getResourceAsStream(EXPECTED_XML));
    String actualXml = IOUtils.toString(ConnectorStrategyStudioXmlTest.class.getClassLoader().getResourceAsStream(ACTUAL_XML));
    Diff diff = new Diff(expectedXml, actualXml);
    diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
    DetailedDiff detailedDiff = new DetailedDiff(diff);
    assertTrue(detailedDiff.toString(), detailedDiff.similar());
}

I've read that using RecursiveElementNameAndTextQualifier class could resolve the problem, but still doesn't work.

Here is an image with an example of the XML comparison failure:

(open in a new tab for full screen) c:

As you can see, both child nodes are inverted

TY in advance. Juan


回答1:


Using a non-default ElementQualifier is the correct solution, but RecursiveElementAndTextQualifier certainly doesn't do what you need.

At first glance it looks as if it should be possible to find the matching elements by looking at the element's name and the value of the caption attribute. If this is correct, then ElementNameAndAttributeQualifier with "caption" passed in as constructor argument should do the trick.

There are more options built into XMLUnit, in the worst case you'd need to implement the ElementQualifier interface yourself if none of the existing options fits your needs.



来源:https://stackoverflow.com/questions/28683449/xmlunit-comparison-failure-because-child-nodes-order

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