XML Diff和Merge [英] XML Diff and Merge

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

问题描述

我认为我有一个相当独特的问题需要解决。好吧,我无法使用谷歌找到足够的信息。这就是它,

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解析器,允许任意大的文件),并将解析的数据存储在单独的HashMaps中。然后,我们使用合并排序类型的算法比较两个地图的内容。

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/)

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

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 Diff和Merge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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