问题描述
我比较一个生成的XML文件与使用XMLunit的另一个示例,并且Im有ChildNodes Order及其属性的问题。
(Linux和Mac版本不同)
这是我试过的:
@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());
}
我读过使用RecursiveElementNameAndTextQualifier类可以解决问题,
下面是一个XML比较失败示例的图片:
(在全新的标签页中打开全屏)c:
子节点被反转
TY。 Juan
使用非默认 ElementQualifier
但 RecursiveElementAndTextQualifier
肯定不会做你需要的。
乍看起来好像应该是可能的通过查看元素的名称和 caption
属性的值来查找匹配元素。如果这是正确的,那么作为构造函数参数传递的 ElementNameAndAttributeQualifier
与caption
>
XMLUnit中内置了更多选项,在最糟糕的情况下,您需要实现 ElementQualifier
现有的选项符合您的需求。
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
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.
这篇关于XMLunit比较失败,因为子节点排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!