XML 差异和合并 [英] XML Diff and Merge

查看:33
本文介绍了XML 差异和合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我有一个相当独特的问题需要解决.好吧,我无法使用 Google 找到足够的信息.就这样吧,

I think i have a rather unique problem to solve. Well, i cant find enough information using Google. So here it goes,

我开发了一个 Java EE SOA 应用程序,该应用程序使用 Oracle XML DB 将 XML 文档存储为 XML.每当 XML 更改时,我都会增加版本并将以前的版本放入不同的表中.

I work on a Java EE SOA application which stores XML documents as XML using Oracle XML DB. Whenever the XML changes, i increment the version and throw the previous version into a different table.

现在的要求是,我应该将两个版本之间的差异存储为 XML,而不是整个 XML 文档.

The requirement now is, I should store the differences between 2 versions as XML, instead of the whole XML document.

  1. 是否有任何可以进行 XML 比较的 Java 库?(XMLUnit,...?)
  2. 是否有用于捕获 XML 差异的标准 XML 架构?
  3. 我可以使用什么转换技术将差异"应用到 XML 以在版本之间来回切换?(XSLT、Groovy ……?)

感谢您的时间.

推荐答案

在我的上一份工作中,我们遇到了类似的问题:我们必须检测两个 XML 文件之间特定项目的更改、插入和删除.这些文件不是任意的 XML;他们必须遵守我们的 XSD.

In my last job, we had a similar problem: We had to detect changes, insertions, and deletions of specific items between two XML files. The files weren't arbitrary XML; they had to adhere to our XSD.

我们的解决方案是实现一种合并排序:解析文件(使用 SAX 解析器,而不是 DOM 解析器,以允许任意大的文件),并将解析的数据存储在单独的 HashMap 中.然后,我们使用归并排序类型的算法比较了两个地图的内容.

Our solution was to implement a kind of merge sort: Parse the files (using a SAX parser, not a DOM parser, to permit arbitrarily large files), and store the parsed data in separate HashMaps. Then, we compared the contents of the two maps using a merge-sort type of algorithm.

当然,文件越大,我们遇到的内存压力就越大,所以我最终编写了一个 FileHashMap 类,将 HashMap 的值空间推送到随机访问文件.虽然理论上较慢,但此解决方案允许我们对非常大的文件进行比较,而不会出现抖动或 OutOfMemoryError 情况.(此库中提供了该 FileHashMap 类的一个版本:http://www.clapper.org/software/java/util/)

Naturally, the larger the files got, the more memory pressure we experienced, so I ultimately wrote a FileHashMap class that pushed the HashMap's value space to random access files. While theoretically slower, this solution allowed our comparisons to work with very large files, without thrashing or OutOfMemoryError conditions. (A version of that FileHashMap class is available in this library: http://www.clapper.org/software/java/util/)

我不知道我刚刚描述的内容是否与您需要的非常接近,但我想我会分享它,以防万一.

I have no idea whether what I just described is even remotely close to what you need, but I thought I'd share it, just in case.

祝你好运.

这篇关于XML 差异和合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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