1

我有两个 XML 文件。它们是相似的,但是有两个节点,其中一个文件只有一个。我想将两组这样的文档合并到一个文档中,首先取 A 面的节点,然后是 B 面的节点。

我不是 diff 工具的经验丰富的用户,我下载了 KDiff3 以从某个地方开始。任何人都可以让我走上正确的道路吗?

--EDIT--
查找差异工具是我可以自己管理的事情。
但是如何制作这些工具中的一个(不管是哪个)通过首先放入 file1 中的部分然后从 file2 中自动进行合并是我正在寻找的。这是一个相当大量的文件,所以我最好不要对合并过程进行任何干预。

4

4 回答 4

1

差异合并。它是免费的,适用于 Windows、Mac OS X 和 Unix。

于 2009-01-21T14:33:15.517 回答
1

这听起来更像是一个软件来创建,然后是软件来查找。

如果您自己滚动,您可以添加额外的检查以确保两个 XML 都有效。

于 2009-01-21T15:17:05.990 回答
1

This might be very problematic to do with a standard diff tool if the xml "nodes" are in any way similar. For example:

file1:

1 <node id="1" />
2 <node id="2a">
3   <content item="1"/>
4   <content item="2a"/>
5 </node>
6 <node id="3" />

file2:

1 <node id="1" />
2 <node id="2b">
3   <content item="1"/>
4   <content item="2b"/>
5 </node>
6 <node id="3" />

A standard diff tool is going to highlight lines 2 and 4 as needing to be merged, but even if you automatically add the lines from file2, you'll end up with an invalid xml file:

1 <node id="1" />
2 <node id="2a">
2 <node id="2b">
3   <content item="1"/>
4   <content item="2a"/>
4   <content item="2b"/>
5 </node>
6 <node id="3" />

You really need a diff/merge tool that is xml-aware. I found a description of one called XmlMerge, along with an example that shows it doing exactly what you're asking for. It's part of EL4J.

There is a dormant effort called XUpdate that has a fair amount of tools around it (both for generating the XUpdate diffs and for applying them). There are also some .net classes that use a different foundation. You will need to do some scripting to use either of these systems I think.

于 2009-01-29T19:29:30.033 回答
0

KDiff3 可以将两个输入版本都放入输出文件。有标记为 A 和 B 的按钮。您可以单击其中一个将一个版本添加到合并结果中。或者您可以同时单击它们,这两个版本都将包含在内。单击这些按钮的顺序将影响插入行的顺序。

它还可以合并整个目录。

唯一的问题似乎是自动化。

KDiff3 的键盘快捷键可以以相当丰富的方式进行配置,所以我会尝试查看这里,然后可能会使用一些键盘脚本应用程序。

可能还有其他更简单的方法:-)

于 2009-01-21T14:36:01.910 回答