开发者

Querying XML using node numbers

Okay, so I'm writing a utility that compares 2 XML documents using Microsoft's XML diff patch tool.

The result looks something like this:

  <?xml version="1.0" encoding="utf-16"?>
  <xd:xmldiff version="1.0" srcDocHash="10728157883908851288" options="IgnoreChildOrder IgnoreComments IgnoreWhitespace " fragments="yes" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
    <xd:node match="1">
     <xd:node match="1">
      <xd:node match="1">
       <xd:node match="2">
        <xd:node match="1">
         <xd:node match="1">
          <xd:node match="2">
           <xd:change match="1">testi22n2123</xd:change>
          </xd:node>
         </xd:node>
        <xd:add match="/1/1/1/2/1/8" opid="1" />
        <xd:node match="7">
         <xd:node match="1">
          <xd:change match="1">31</xd:change>
         </xd:node>
         <xd:node match="2">
          <xd:change match="1">test2ing</xd:change>
         </xd:node>
        </xd:node>
        <xd:remove match="8" opid="1" />
       </xd:node>
      </xd:node>
     </xd:node>
    </xd:node>
   </xd:node>
   <xd:descriptor opid="1" type="move" />
  </xd:xmldiff>

What I'm trying to do is go back into the source document and get the source data that represents the difference. I initially tried creating an Xpath query, but as I understand it now this XmlDiff thing works off the DOM开发者_StackOverflow中文版... which seems like the dinosaur of XML objects these days.

What's the best way to get at the node in the source XML by using the numbers provided in the diff result?

UPDATE: hmmm... I can't seem to locate the source for XmlDiffPatch.View, outside of the XmlDiff and the XmlDiffPatch.View samples. The current XmlDiffPatch.View class only offers "GetHtml", which is fine if you want to use their output style, but won't work with what I need to do. Ideally I'd like to add a method that would just return the XML of the differences, with some indication of what was added, changed, or deleted. Then using some XSLT I can view it any way I want (or do other stuff with it).

So, the question is answered - this definitely works for what I asked, but I'm wondering if anyone has seen the source out there?


You'll find the answers here:

http://msdn.microsoft.com/en-us/library/aa302295.aspx#xmldif_topic3

As they say "parsing this code and applying the changes specified in the diffgram is not trivial"

You'll need to understand the diffgram format to do what you want to, but it is all there.

The XPath/DOM question sounds like a blind alley for you - they are about how the processing is done, whereas you seem to be stuck on the what of processing the diffgram.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜