xml - 如何比较 XML 文档

标签 xml comparison xmldiff

我需要比较两个 XML block :

<elem type="p:type1" xmlns:p="myns" />

<elem type="g:type1" xmlns:g="myns" />

一旦我们看到 type 属性是 QName 而不仅仅是一个字符串,它们在语义上是等价的。一旦我提供了架构,是否有可以进行此类比较的工具?还有,有没有这样的API?

最佳答案

可能有很多工具可以执行此操作,其中之一是 Xml Diff 和 Path,来自 MS XML downloads

The Microsoft XML Diff and Patch utility can be used for comparing two XML documents and then patching the original document with the differences, to create a final document. The utility can detect structural changes (such as the move of an XML subtree) and can create an Xml Diff Language Diffgram (XDL diffgram or just diffgram) that describes the differences between the two XML documents. The diffgram can then be used to display these differences or perform a patch using the XML Patch tool.

XML Diff performs XML-based comparison of the XML documents, as opposed to a common lexical comparison. Therefore, it

Ignores the order attributes. Ignores insignificant white spaces. Does not differentiate between an empty element () and element with no content (). Does not care about the document encoding.

这些工具可通过命令行和 API 使用。

关于xml - 如何比较 XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/959918/

相关文章:

.net - 防止 XmlTextReader 扩展实体

java - 获取一个 ArrayList,其中包含某些对象类型的两个不同大小的 arraylist 的并集

.net 3.5 中深度/递归对象比较的 C# 实现

c# - 在 C# 中寻找高性能 XyDiff 端口(带有 XID 的 XML Diff 补丁)

java - 使用 FileProvider 处理 XML 文件的数据

Java:SAXParser字符引用解码

android - 如何制作一个 GridLayout,其中元素平均填充网格?

c# - 获取两个字符串的公共(public)前缀

XML 差异的 JavaScript 实现