合并 XML 文档 [英] Merge XML documents
问题描述
我需要合并"两个 XML 文档,覆盖重叠的属性和元素.例如,如果我有 document1:
I need to "merge" two XML documents, overwriting the overlapsed attributes and elements. For instance if I have document1:
<mapping>
<key value="assigned">
<a/>
</key>
<whatever attribute="x">
<k/>
<j/>
</whatever>
</mapping>
和document2:
<mapping>
<key value="identity">
<a/>
<b/>
</key>
</mapping>
我想像这样合并两者:
<mapping>
<key value="identity">
<a/>
<b/>
</key>
<whatever attribute="x">
<k/>
<j/>
</whatever>
</mapping>
我更喜欢基于 Java 或 XSLT 的解决方案,ant 会很好,但如果在 中有一种简单的方法可以做到这一点>Rake、Ruby 或 Python 请不要害羞:-)
I prefer Java or XSLT-based solutions, ant will do fine, but if there's an easy way to do that in Rake, Ruby or Python please don't be shy :-)
实际上我发现我更愿意使用自动化工具/脚本,甚至 自己编写,因为手动合并大约 30 个 XML 文件有点笨拙...... :-(
actually I find I'd rather use an automated tool/script, even writing it by myself, because manually merging some 30 XML files is a bit unwieldy... :-(
推荐答案
如果您喜欢 XSLT,这里有一个我以前用过的不错的合并脚本:Oliver 的 XSLT 页面
If you like XSLT, there's a nice merge script I've used before at: Oliver's XSLT page
这篇关于合并 XML 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!