XMLUnit-2 比较部分XML。

huangapple go评论75阅读模式
英文:

XMLUnit-2 compare partial XMLs

问题

我有一个名为test的本地XML数据,如下所示:

testLocalXML

<root>
  <elementA>something different</elementA>
  <elementB>something else</elementB>
  <elementC>yet another thing</elementC>
</root>

但是,我从服务器获取的数据可能会很大,并且会不断动态增加,例如:

服务器响应

<root>
  <elementA>something different</elementA>
  <elementB>something else</elementB>
  <elementC>yet another thing</elementC>
  <elementD>next data</elementD>
  <elementE>another data</elementE>
  <elementF>F data</elementF>
  .
  .
  ... 等等...
</root>

我不知道可以使用以下逻辑忽略哪个node。我的节点是动态的。

.withNodeFilter(node -> !(node.getNodeName().equals("elementD") ||
                          node.getNodeName().equals("elementE"))

在这种情况下,由于服务器响应是动态的并且不断增加,我如何使用XMLUnit验证我在testLocalXML中提到的数据?

英文:

I have a local test XML data as below

testLocalXML

<root>
  <elementA>something different</elementA>
  <elementB>something else</elementB>
  <elementC>yet another thing</elementC>
</root>

but the data I'm getting from server could be large and will keep dynamically increasing e.g.

Server Response

<root>
  <elementA>something different</elementA>
  <elementB>something else</elementB>
  <elementC>yet another thing</elementC>
  <elementD>next data</elementD>
  <elementE>another data</elementE>
  <elementF>F data</elementF>
  .
  .
  ... so on...
</root>

I don't know which node I can ignore using below logic. My node are dynamic.

.withNodeFilter(node -> !(node.getNodeName().equals("elementD") ||
                          node.getNodeName().equals("elementE"))

Here, as server response is dynamic and keep on increasing how would I validate whatever data I mentioned in the testLocalXML using XMLUnit?

答案1

得分: 0

好的,以下是翻译好的部分:

我确实知道我感兴趣的元素,所以我可以轻松地执行以下操作:

final Collection<String> expected = Arrays.asList("root", "elementA", "elementB", "elementC");

并且可以添加过滤器,如下所示:

.withNodeFilter(n -> expected.contains(n.getNodeName()))
英文:

Well, I do know the elements that I'm interested in, so I could easily do

  final Collection&lt;String&gt; expected = Arrays.asList(&quot;root&quot;, &quot;elementA&quot;, elementB&quot;, &quot;elementC&quot;);

And can add filter as

  .withNodeFilter(n -&gt; expected.contains(n.getNodeName()))

huangapple
  • 本文由 发表于 2020年4月10日 19:23:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/61139266.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定