C# 获取输出diffgram中的节点名,而不是它们的索引

C# 获取输出diffgram中的节点名,而不是它们的索引,c#,xml,C#,Xml,我正在使用XMLdiffpatch工具检测两个xml文件之间的更改,该工具的输出xml文件如下所示: <?xml version="1.0" encoding="utf-16"?> <xd:xmldiff version="1.0" srcDocHash="5708212576896487287" options="None" fragments="no" xmlns:xd="http://www.microsoft.com/xmldiff"> <xd:no

我正在使用
XMLdiffpatch
工具检测两个xml文件之间的更改,该工具的输出xml文件如下所示:

<?xml version="1.0" encoding="utf-16"?>
<xd:xmldiff version="1.0" srcDocHash="5708212576896487287" options="None" fragments="no" xmlns:xd="http://www.microsoft.com/xmldiff">
    <xd:node match="2">
        <xd:node match="3"/>
        <xd:add>
            <e>Some text 4</e>
            <f>Some text 5</f>
        </xd:add>
        <xd:node match="4">
            <xd:change match="1">Changed text</xd:change>
            <xd:remove match="2"/>
        </xd:node>
        <xd:node match="5">
            <xd:remove match="@secondAttr"/>
            <xd:add type="2" name="newAttr">new value</xd:add>
            <xd:change match="@firstAttr">changed attribute value</xd:change>
        </xd:node>
        <xd:remove match="6" opid="1"/>
        <xd:add type="1" name="p">
            <xd:add type="1" name="q">
                <xd:add match="/2/6" opid="1"/>
            </xd:add>
        </xd:add>
    </xd:node>
    <xd:descriptor opid="1" type="move"/>
</xd:xmldiff>

一些文本4
一些文本5
更改文本
新价值
更改属性值
第一个文件:

<?xml version="1.0"?>
<b>
  <a>Some text 1</a>
  <b>Some text 2</b>
  <c>Some text 3</c>
  <d>
    Another text
    <foo/>
  </d>
  <x firstAttr="value1" secondAttr="value2"/>
  <y>
    <!--Any comments?-->
    <z id="10">Just another text</z>
  </y>
</b>

一些文本1
一些文本2
一些文本3
另一个文本
只是另一个文本
第二个文件:

<?xml version="1.0"?>
<b>
  <a>Some text 1</a>
  <b>Some text 2</b>
  <c>Some text 3</c>
  <e>Some text 4</e>
  <f>Some text 5</f>
  <d>Changed text</d>
  <x firstAttr="changed attribute value" newAttr="new value"/>
  <p>
    <q>
      <y>
        <!--Any comments?-->
        <z id="10">Just another text</z>
      </y>
    </q>
  </p>
</b>

一些文本1
一些文本2
一些文本3
一些文本4
一些文本5
更改文本

只是另一个文本

如您所见,xml在其索引对应于其父节点时显示检测到的节点更改。
我现在面临的问题是如何解析这些索引,以便用原始xml文件中的实际节点名替换它们。

在xml diff中看到的“匹配”数字是子节点的相对索引。构建整个XMLDiff是为了从第一个文件构造第二个文件。以你为例,

<xd:node match="2">
  <xd:node match="3"/>
    <xd:add>
        <e>Some text 4</e>
        <f>Some text 5</f>
    </xd:add>

一些文本4
一些文本5
这意味着:

“在第一个文件中,找到根目录中的第二个子节点”-即节点 声明之后

“在找到的节点中,找到第三个子节点”-即某些文本3

“找到节点后,插入以下文本”-插入节点e和f

有一篇关于MSDN的非常详细的文章,其中包含一些代码示例和xmldiff语言规范


所以,为了用实值替换索引,您需要根据diff索引遍历源文档,并提取实数节点名。有很好的代码示例来遍历子节点。

是的,一个c#console应用程序您需要发布两个xml文件,在这些文件中输入XMLDiffPatch作为数据是没有意义的。非常抱歉,从第一次开始就没有这样做!!我上传了它们并编辑了我的原始帖子是的,所以现在我看到了你的问题。这里的索引并不是特别有用,它们显然对XMLPatch类有一定的意义。我假设索引是从它解析文档中节点的方式得到的数字。可能会在微软论坛上询问,有人可能会在那里提供帮助吗?对不起,我帮不上忙了。