将类似的xml文件与XmlUnit与无序标记进行比较(具有不同属性的相同标记名称) [英] Comparing similar xml files with XmlUnit with unordered tags (same tag name with different attributes)

查看:327
本文介绍了将类似的xml文件与XmlUnit与无序标记进行比较(具有不同属性的相同标记名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试成功运行XmlUnit,对我的工作非常有帮助。现在,我有一点问题,我不知道如何解决。我有一个java类,它有一个Set,当它转换成XML时,里面的元素可以有任何顺序。

I am trying successfully XmlUnit, and is very helpful in my job. Now, I have a little problem, that I don't know how to solve. I have a java class, that has a Set, and when transforming it into XML, the elements inside can have any order.

当我在XmlUnit中尝试这两个文件时工作(Diff说他们是相似的):

When I try these two files in XmlUnit it works (Diff says that they are similar):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Monitor>
    <AvailableMeasures>
        <MeasureDescriptorA name="netInput_mynetwork"></MeasureDescriptorA>
        <MeasureDescriptor name="netInput_myothernetwork"></MeasureDescriptor>
    </AvailableMeasures>
</Monitor>



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Monitor>
    <AvailableMeasures>
        <MeasureDescriptor name="netInput_myothernetwork"></MeasureDescriptor>
        <MeasureDescriptorA name="netInput_mynetwork"></MeasureDescriptorA>
    </AvailableMeasures>
</Monitor>

但是当标签具有相同的名称(具有不同的属性)时,它不起作用(它混合属性,并期望在另一个标记中的那个:)

But when the tags have the same name (with different attributes) it doesn't work (it mixes the attributes, and expect the one in the other tag):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Monitor>
    <AvailableMeasures>
        <MeasureDescriptor name="netInput_myothernetwork"></MeasureDescriptor>
        <MeasureDescriptor name="netInput_mynetwork"></MeasureDescriptor>
    </AvailableMeasures>
</Monitor>



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Monitor>
    <AvailableMeasures>
        <MeasureDescriptor name="netInput_mynetwork"></MeasureDescriptor>
        <MeasureDescriptor name="netInput_myothernetwork"></MeasureDescriptor>
    </AvailableMeasures>
</Monitor>

有解决方法吗?

推荐答案

我自己找到了解决方案。

I found the solution by myself.

Diff diff = new Diff(controlXml, responseXml);
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());

这篇关于将类似的xml文件与XmlUnit与无序标记进行比较(具有不同属性的相同标记名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆