XML representation

Fields shall be implemented in XML using either of two approaches:

  • As a simple field implementation, using the <fldSimple> element, or

  • As a complex field implementation, using a set of runs involving the <fldChar> and <instrText> elements.

For a simple field implementation, only one element, <fldSimple>, shall be used, in which case, its @instr attribute shall contain a field, and the body of the element shall contain the most recently updated field result.
example: : Here is the corresponding XML for a simple field implementation of DATE:
<w:r>
  <w:fldSimple w:instr="DATE"> 12/31/2005 </w:fldSimple>
</w:r>

For a complex field implementation, a set of runs shall be used with each run containing, in sequence, the following elements:

  • <fldChar> with attribute @fldCharType value begin,

  • One or more <instrText> elements, which, collectively, contain a complete field,

  • Optionally,

    • <fldChar>< >with attribute @fldCharType value separate, which separates the field from its field result,

    • Any number of runs and paragraphs that contains the most recently updated field result, and

  • <fldChar> with attribute @fldCharType value end.

Note:
<w:r>
  <w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
  <w:instrText xml:space="preserve"> DATE </w:instrText>
</w:r>
<w:r>
  <w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r>
  <w:t>12/31/2005</w:t>
</w:r>
<w:r>
  <w:fldChar w:fldCharType="end"/>
</w:r>
Note:

As shown in §2.16.1, the instruction of one field can be another field, allowing fields to nest. In such cases, the XML run sequence for the inner field is defined at the point of reference for that inner field, inside the outer field's XML run sequence. [: Consider the following sentence:

It's IF DATE \@ "M-d"<>"1-1" "not " new year's day.

The IF field contains the nested field DATE \@ "M-d". When updated, on January 1 of any year, the result sentence is "It's new year's day." On all other days of the year, the resulting sentence is "It's not new year's day."

Here is one way of writing the corresponding XML:

<w:r>
  <w:t xml:space="preserve">It’s </w:t>
</w:r>
<w:r …>
  <w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
  <w:instrText xml:space="preserve">IF </w:instrText>
</w:r>
<w:r>
  <w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
  <w:instrText xml:space="preserve"> DATE  \@ "M-d"  </w:instrText>
</w:r>
<w:r>
  <w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r …>
  <w:instrText>1-4</w:instrText>
</w:r>
<w:r>
  <w:fldChar w:fldCharType="end"/>
</w:r>
<w:r>
  <w:instrText>&lt;&gt;"1-1" "not "</w:instrText>
</w:r>
<w:r …>
  <w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r …>
  <w:t xml:space="preserve">not </w:t>
</w:r>
<w:r …>
  <w:fldChar w:fldCharType="end"/>
</w:r>
<w:r>
  <w:t>new year’s day!</w:t>
</w:r>