Representing XML Attribute Change in diff3x

XML attributes present a particular challenge for diff3 format, and this can be improved using an XML representation.

It is worth noting an issue with the diff3 format in this situation, because it is quite subtle but one that we can resolve in diff3x. The lines in the input files at which all three files align (the lines are all equal) are considered 'anchor' points. All of the lines between anchor points is considered to be a single choice - and when there is some kind of conflict then the choice is left for the user to select. The interesting consequence of this structure is that it is not possible to have two consecutive choices without a separator which requires a commonality between all three files, i.e. an anchor point. For structured data it would be natural, for example, to provide choices about attributes in a manner that allows each attribute to be chosen separately, but the diff3 format dictates that two adjacent changes are seen as one choice.

We can improve this with diff3x because we can easily have adjacent choices without any ambiguity.

Table 6. XML Attribute value change

A.txtO.txtB.txt
<span class="two" 
  dir="rtr" id="23">
<span class="one" 
  id="23" dir="TBA">
<span id="23" 
  class="three" dir="ltr">


These changes can be represented in diff3x as shown below.

<diff3x a="A.txt" b="B.txt" o="O.txt">
<![CDATA[<span id="23"]]>
<choice3>
<a>class="two"</a>
<o>class="one"</o>
<b>class="three"</b></choice3>

<choice3>
<a>dir="rtr"</a>
<o>dir="TBA"</o>
<b>dir="ltr"</b></choice3>
<![CDATA[</span>]]></diff3x>

There is another representation that takes the common attribute name out of the choice but this may be less easy for a user to see what is happening by inspection of the diff3x but a GUI could provide an intuitive interface. For illustration, in the first class attribute we have included the attribute value quotation marks in the options, and for the dir attribute we have put them outside - this is a matter of choice, either approach can be represented by diff3x.

<diff3x a="A.txt" b="B.txt" o="O.txt">
<![CDATA[<span 
class=]]><choice3><a>"two"</a>
                <o>"one"</o>
                <b>"three"</b></choice3>
dir="<choice3><a>rtr</a>
            <o>TBA</o>
            <b>ltr</b></choice3>"
<![CDATA[</span>]]></diff3x>