Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I’m using XMLdiffpatch tool to detect changes between two xml files , the output xml file of the tool looks like this :

<?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>
First File :

<?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>
Second file :

<?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>
as you see , the xml displays the detected node changes upon their index corresponding to their parent nodes .
The problem I’m facing now is how to parse these indexes , in order to replace them with their actual node names in the original xml file .
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900