使用BeyondCompare在XML比较中排除的规则

时间:2013-03-19 21:43:51

标签: beyondcompare

在比较xml文件时,我需要在比较中添加一条规则。我需要忽略以包含单词exclude="true"的内容开头的节点 并以</File>

结尾
  <File name="LogData.txt" exclude="true" type="TIMESTAMP">
   <Date>2012-09-27 17:43:36.211</Date>
  </File>

我已设法为我的示例实例创建一个规则,如下所示:

从:<File name="LogData.txt" exclude="true"开头 结束于:</File>

但是我需要一些更通用的东西,它会忽略任何包含exclude =“true”属性的File节点。

1 个答案:

答案 0 :(得分:0)

你的解决方案是什么? 您是否尝试使用这样的正则表达式: enter image description here

Text from-expression <File (.*)exclude="true".*尽可能频繁地表达任何字符

另一种解决方案是使用外部转换。

我写了这样的e litte ruby​​-script:

File.open(ARGV.last, "w"){|f|
  f.write(File.read( ARGV.first).gsub( %r{<(.+?)\s[^>]+exclude="true".*?>(.*?)</\1>}m, ""))
}

它将第一个参数作为源文件名,并将转换后的xml写入目标文件。

此脚本可用作转换工具:

enter image description here

这个比较: enter image description hereenter image description here

而不是脚本,我也成功使用了一个班轮

ruby​​ -e&#34; File.open(&#39;%t&#39;,&#39; w&#39;){| f | f.write(File.read(&#39;%s&#39;)。gsub(/]+exclude=.true..?>(.?)</File>/ m,&#39;&#39;)}}&#34;

如果您将脚本改编为

File.open(ARGV.last, "w"){|f|
  f.write(File.read( ARGV.first).gsub( %r{(<(.+?)\s[^>]+exclude="true".*?>(.*?)</\2>)}m, "<!--\n\\1\n-->"))
}

排除的部分未被删除,但设置为评论(<!-- ... -->),您会得到: enter image description here

差异现在是一个不重要的差异(蓝色而不是红色),你可能会忽略这种差异。

说明: *如果你想使用我的脚本,你需要红宝石。 *如果需要,您可以用其他语言编写转换脚本。 *我使用的正则表达式未经过充分测试。嵌套标签可能有问题。