使用Powershell比较两个xml文档和打印差异,其中包括父路径

时间:2016-10-28 22:30:48

标签: xml powershell path location compare

我想在 Powershell 中找到一种方法来比较两个xml文档,其中脚本将打印&#39;差异项<&#39; 并为每个差异包括父路径。

我有两个我想比较的XML文件。

文件A(XML):

<products>
  <product name="demo">
    <addresslist type="IPv4">
      <address>8.8.8.8</address>
    </addresslist>
    <addresslist type="URL">
      <address>boom.com</address>
    </addresslist>
  </product>
</products>

文件B(XML ,其中 <address>4.4.4.4</address> 是不同的):

<products>
  <product name="demo">
    <addresslist type="IPv4">
      <address>8.8.8.8</address>
      <address>4.4.4.4</address>
    </addresslist>
    <addresslist type="URL">
      <address>boom.com</address>
    </addresslist>
  </product>
</products>

我的Powershell脚本是这样的:

$A_xml = ("A-file.xml")

$B_xml = ("B-file.xml")

Compare-Object -ReferenceObject (Get-Content $A_xml) -DifferenceObject (Get-Content $B_xml)

不幸的是,结果是:

<address>4.4.4.4</address>         <=

我希望得到的结果是:

<products>
  <product name="demo">
    <addresslist type="IPv4">
      <address>4.4.4.4</address>
    </addresslist>
  </product>
</products>

其中包括差异项的父路径。

0 个答案:

没有答案