简体   繁体   English

如何明智地比较 SoapUI 中的两个 XML 文件?

[英]How to wisely compare two XML files in SoapUI?

I have a situation where two different webservice methods should return exactly the same XML file.我遇到过两种不同的 webservice 方法应该返回完全相同的 XML 文件的情况。

Right now when I get those two responses I compare those XML files using XMLUnit framework which shows xpath location + differences in various nodes like in the following code:现在,当我得到这两个响应时,我使用 XMLUnit 框架比较了这些 XML 文件,该框架显示了 xpath 位置 + 各个节点中的差异,如下面的代码所示:

XMLUnit.setIgnoreWhitespace(true);
DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(firstXML,secondXML));
List<Difference> allDiifferences= diff.getAllDifferences();

for(Difference difference : allDiifferences){
    System.out.println(difference.getControlNodeDetail().getXpathLocation()+" ("+difference.getControlNodeDetail().getValue()+") /("+difference.getTestNodeDetail().getValue()+")");
}

When I am running the tests in SoapUI I use当我在 SoapUI 中运行测试时,我使用

log.info
log.error

methods to show the differences which are storred in XMLs.显示存储在 XML 中的差异的方法。

Is there any better way to show those differences?有没有更好的方法来显示这些差异?

I have done some R&D about this and this is what i can tell you, to the best of my knowdledge.我已经对此进行了一些研发,据我所知,这就是我可以告诉你的。 XMLUnit offers the most stable and lightweight tools that can effectively find a variety of differences between two xml files. XMLUnit 提供了最稳定和轻量级的工具,可以有效地找到两个 xml 文件之间的各种差异。 Ofcourse you have the liberty of choosing how to show these differences once they are found.当然,一旦发现这些差异,您可以自由选择如何显示这些差异。

XMLUnit is good for your use case. XMLUnit 适合您的用例。 or you can try alternative approach of using JAXB to convert XML to Java Objects and then write your custom comparators.或者您可以尝试使用 JAXB 将 XML 转换为 Java 对象的替代方法,然后编写您的自定义比较器。 (JAXB tools can auto generate classes from your DTDs) (JAXB 工具可以从您的 DTD 自动生成类)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM