小编Ham*_*ami的帖子

Groovy:将SOAP响应与XML文件进行比较

我想在groovy代码中比较我的Soap Response和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())
Run Code Online (Sandbox Code Playgroud)

所以,正如你所看到的,我使用了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>
Run Code Online (Sandbox Code Playgroud)

我的问题是我无法保证ValueA是第一个而不是第二个

xml groovy compare xmlunit xmlunit-2

2
推荐指数
1
解决办法
1607
查看次数

标签 统计

compare ×1

groovy ×1

xml ×1

xmlunit ×1

xmlunit-2 ×1