本文介绍了XmlUnit可以替代吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要比较包含生成的.xml和.wsdl文件的大型目录结构.生成的.xml文件在子元素出现的顺序上有所不同. XmlUnit Diff.similar()方法应该可以处理这种情况:

I need to diff large directory structures containing generated .xml and .wsdl files. The generated .xml files differ in the order that child elements appear. The XmlUnit Diff.similar() method is supposed to handle this case:

如果两个文档包含相同的元素和属性,而不考虑其顺序,则认为它们是相似的".

'Two documents are considered to be "similar" if they contain the same elements and attributes regardless of order.'

但是,情况并非如此.我拿了一个.xml文件,颠倒了两个子元素的顺序,XmlUnit说它们不相似.

This is not the case, however. I took a .xml file, reversed the order of two child elements and XmlUnit says that they are not similar.

XmlUnit损坏,仅提供了比内置diff实用程序更多的功能.

XmlUnit is broken, providing no more functionality than the built-in diff utility.

XmlUnit是否可以识别.xml文件中的简单差异(例如子元素的排序)?

Is there an alternative to XmlUnit that recognizes simple differences in .xml files like ordering of child elements?

推荐答案

我有一个类似的问题,就我而言,我有几个具有相同名称但属性不同(顺序无关紧要)的标签,但是XmlUnit总是先检查第一,再检查第二...可以交换.我的问题是:

I have a similar problem, in my case, I had several tags with the same name, but different attributes (the order didn't matter), but XmlUnit always checked first with first, second with second... that could be swapped. My question was:

比较相似的xml带有XmlUnit且标签无序的文件(具有不同属性的相同标签名)

我在这里找到了解决方案:

I found a solution here:

http://www.infoq.com/articles/xml-unit-test

就我而言,它是通过覆盖元素限定符解决的:

In my case, it was solved just overriding the element qualifier:

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

这篇关于XmlUnit可以替代吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 02:26