【发布时间】:2016-11-22 13:53:00
【问题描述】:
我想在 groovy 代码中比较我的 Soap 响应与忽略顺序的 xml 文件:
这是我的代码:
import org.custommonkey.xmlunit.Stuff
import org.xmlunit.Stuff
//ExpectedString is my xml converted to text, same for ResponseString
Diff diff = DiffBuilder.compare(ExpectedString)
.withTest(ResponseString)
.ignoreComments()
.ignoreWhitespace()
.checkForSimilar()
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName))
.build();
assertFalse("XML similar " + diff.toString(), diff.hasDifferences())
所以,如您所见,我使用了 DefaultNodeMatcher,我使用了 XMLUnit2.0 ...没有结果(甚至没有忽略顺序或比较时出现异常错误)
有解决办法吗?解决这个问题
由于我迫切地想找到一个直接的,我可以对我的 xml 和我的肥皂响应进行排序,以便我可以有一个简单的差异吗?有没有办法按字母顺序逐行排序?如果是,如何?
谢谢你们!
更新:
这是我的 XML 结构简化
<body>
<stuff>
<miniStuff></miniStuff>
<miniStuff></miniStuff>
</stuff>
<Services>
<Service>
<tag1>ValueA</tag1>
<tag2>ValueAA</tag2>
</Service>
<Service>
<tag1>ValueB</tag1>
<tag2>ValueBB</tag2>
</Service>
</services>
</body>
我的问题是我不能保证 ValueA 是第一个而不是第二个
【问题讨论】:
-
您有想要比较的样本数据吗?
-
我会在一分钟内将一个简单的数据添加到我的帖子中,谢谢 :)
-
@Rao : 准备好了兄弟 :)
标签: xml groovy compare xmlunit xmlunit-2