有没有人知道比较两个XML文档的工具。嘲笑那个......还有更多。我需要一些东西来确保文件1中的每个节点也在文件2中,而不管顺序如何。我认为XML Spy会使用忽略子节点顺序选项,但事实并非如此。以下内容将被视为相同:
<Node>
<Child name="Alpha"/>
<Child name="Beta"/>
<Child name="Charlie"/>
</Node>
<Node>
<Child name="Beta"/>
<Child name="Charlie"/>
<Child name="Alpha"/>
</Node>
你可能想谷歌“XML diff工具“,这将给你带来更多的结果。
其中之一是 OxygenXml,我经常使用的工具。您也可以尝试微软 XML差异和补丁工具。
祝你好运。
我为此编写了一个简单的python工具 xmldiffs
:
比较两个XML文件,忽略元素和属性顺序。
用法: xmldiffs [OPTION] FILE1 FILE2
任何额外的选项都会传递给 diff
命令。
得到它 https://github.com/joh/xmldiffs
我用了 XMLUnit测试 因为它可以满足不同顺序的元素。
今天晚上我有类似的需求,找不到符合我要求的东西。
我的解决方法是对我想要的两个XML文件进行排序,按元素名称的字母顺序排序。一旦它们处于一致的顺序,我就可以使用常规的可视化差异工具来区分两个已排序的文件。
如果这种方法听起来对其他任何人都有用,我就已经分享了我编写的python脚本来进行排序 http://dalelane.co.uk/blog/?p=3225
作为一种(非常)快速而肮脏的方法,我在紧要关头做到了这一点:
- 打开Excel
- 将文件1粘贴到A列中,每行一行。将范围命名为“FILE1”
- 将文件2粘贴到B列,每行一行。将范围命名为“FILE2”
在C1中,输入公式:
=IF(ISERROR(VLOOKUP(B1,FILE1,1,FALSE)),"DIFF","")
在D1中,输入论坛:
=IF(ISERROR(VLOOKUP(A1,FILE2,1,FALSE)),"DIFF","")
- 将列C和D填入文件底部。
这将突出显示在一个文件中而不是另一个文件中的任何行。任何方面都不整齐,但有时候你只需要处理你所拥有的东西。
同 超越比较 你可以在 File Formats
- 设置 XML Sort
转换。使用此选项,XML子项将在diff之前排序。
Beyond Compare的路径/便携版本是 可得到。
/**
* @author sdiallo
* @since 2017-01-16
* <p>
* Compare the content of two XML file
* </p>
* <ul>
* <li>Ignore the white space</li>
* <li>Ignore the attribute order</li>
* <li>Ignore the comment</li>
* <li>Ignore Sequence child nodes are not the same</li>
* <ul>
*
* @param String XML
* first Content to be compared
* @param String XML
* second Content to be compared
* @return List the differences computed between the two files
* <ul>
* <li>null means the files are equal</li>
* <li>elsewhere the files are different</li>
* <ul>
* */
public static List buildDiffXMLs(String xmlExpected, String xmlGenerated) {
List<?> differencesList = null;
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreWhitespace(true);
try {
DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(
xmlExpected, xmlGenerated));
// Two documents are considered to be "similar" if they contain the
// same elements and attributes regardless of order.
if ( !diff.identical() && !diff.similar()) {
differencesList = diff.getAllDifferences();
}// end if
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return differencesList;
}// buildDiffXMLs