Nested Changes

As diff3x is an XML representation we here consider going one step further and making use of the fact that the representation is hierarchical to support hierarchical or 'nested' change. A nested change is a change in one branch that modifies something that has been removed in another branch.

We will look at an XML example, showing nested changes.

Table 7. XML nested data example

A.xmlO.xmlB.xml
<author>
<personname>
 <first>Nigel</first>
 <last>Whitaker</last>
</personname>
<address>
 <ph>01684 532141</ph>
 <st>Geraldine Rd</st>
 <city>Malvern</city>
 <country>UK</country>
 <post>WR14 3SZ</post>
</address>
</author>
<author>
<personname>
 <first>Nigel</first>
 <last>Whitaker</last>
</personname>
<address>
    
 <st>Geraldine Rd</st>
 <city>Malvern</city>
 <country>UK</country>
 <post>WR14 3SZ</post>
</address>
</author>
<author>
<personname>
 <first>Nigel</first>
 <last>Whitaker</last>
</personname>







</author>

In the above example one branch, B.xml, has deleted the address sub-tree which the other branch has modified with an added phone number. As we are now using an XML representation that has a tree structure we can also make use of this structure in the result.

In order to distinguish between a simple <ao> option and a nested choice, we introduce the <aoChoice> element. This is a mixed content element that can include <a> or <o> elements as well as text.

<d:diff3x a="A.xml" b="B.xml" o="O.xml"><![CDATA[
<author>
<personname>
 <first>Nigel</first>
 <last>Whitaker</last>
</personname>]]>
<d:choice3>
 <d:aoChoice include="true"><![CDATA[
   <address>]]>
     <d:a><![CDATA[
      <ph>+44 1684 532141</ph>]]>
     </d:a>
    <![CDATA[
    <st>Geraldine Rd</st>
    <city>Malvern</city>
    <country>UK</country>
    <post>WR14 3SZ</post>
   </address>]]>
  </d:aoChoice>
  <d:bChoice/>
 </d:choice3><![CDATA[
</author>]]>
</d:diff3x>

Here we can see that by allowing nested change we can avoid the repetition and make it easier for a human to understand. However, in order to support this in the format we have to introduce quite a number of new elements and different rules. This adds to the complexity of the format and moves us a lot further away from the original elegant simplicity of diff3. Keeping diff3x as simple as possible seems preferable to including the ability to represent a subset of changes as nested changes.

For this reason we have elected not to include the ability to represent nested changes in diff3x.