我正在使用xmlunit比较两个文本文件。控件xml为:
<books>
<book>
<name>Angels & Demons</name>
<isbn>9971-5-0210-0</isbn>
<author>Dan Brown</author>
<category></category>
</book>
</books>我正在将其与交换了和元素的另一段xml进行比较。
<books>
<book>
<isbn>9971-5-0210-0</isbn>
<name>Angels & Demons</name>
<author>Dan Brown</author>
<category></category>
</book>
</books>Diff对象报告以下差异:
Expected sequence of child nodes '1' but was '3' - comparing <name...> at /books[1]/book[1]/name[1] to <name...> at /books[1]/book[1]/name[1]如果<name>是子节点“%1”,<isbn>不是子节点“%2”吗?
发布于 2013-05-22 22:11:36
看起来XmlUnit将xml中的回车计算为子节点。设置以下XMLUnit.setIgnoreWhitespace(true);提供了更直观的子节点“0”但为“1”的预期序列的结果-比较<int...> at /struct[1]/int[1] to <int...> at /struct[1]/int[1]
发布于 2016-02-19 15:48:21
xmlUnit 2.X版本的:
对于xmlUnit 2.xx版本,XMLUnit.setIgnoreWhitespace(true)不再适用。现在,您可以通过添加DiffBuilder.ignoreWhitespace()将“忽略空格”直接添加到DiffBuilder。
Diff diffXml =DiffBuilder.compare(expectedXml).withTest(actualXml).normalizeWhitespace().checkForSimilar().build();要断言这两个xmls是相似的,您可以例如。执行以下操作:
MatcherAssert.assertThat(diffXml.toString(), is("[identical]"));有关1.x到2.x之间更改的更多信息,请参阅:https://github.com/xmlunit/user-guide/wiki/Migrating-from-XMLUnit-1.x-to-2.x
https://stackoverflow.com/questions/16682486
复制相似问题