[Table of Contents] [docx version]

WordprocessingML Reference Material - Table of Contents

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>

end example]

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: Fields that are for display purposes only have no need to, and do not, store a field result. end note][Example: Here is the corresponding XML for a complex field implementation of DATE:

<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>

end example]

[Note: Every simple field implementation for a given field has a corresponding complex field implementation. However, not every complex field implementation has a corresponding simple field implementation. If some characters in a field have different run properties than others, that field must be implemented using multiple runs, and that requires that complex field implementation be used. For an example, see §2.16.4.3, where the first letter of a DATE field is made bold, underlined, and red, while the other letters have none of these properties. end 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. [Example: 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>

end example]