英文:
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<String> expected = Arrays.asList("root", "elementA", elementB", "elementC");
And can add filter as
.withNodeFilter(n -> expected.contains(n.getNodeName()))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论