Smart Tags

The first example of customer-defined semantics which can be embedded in a WordprocessingML document are smart tags. Smart tags allow semantic information to be added around an arbitrary run or set of runs within a document to provide information about the type of data contained within.

Consider the following text in a WordprocessingML document, with a smart tag around the stock symbol 'CNTS' (where the smart tag is displayed using a purple dotted underline):

This text would translate to the following WordprocessingML markup:

<w:p w:rsidR="00672474" w:rsidRDefault="00672474">
  <w:r>
    <w:t xml:space="preserve">This is a stock symbol: </w:t>
  </w:r>
  <w:smartTag w:uri="http://schemas.openxmlformats.org/2006/smarttags" 
     w:element="stockticker">
    <w:r>
      <w:t>MSFT</w:t>
    </w:r>
  </w:smartTag>
</w:p>

As shown above, the smart tag is delimited by the <smartTag> element, which surrounds the run (or runs) which contain the text which is part of the smart tag.

The smart tag itself carries two required pieces of information, which together contain the customer semantics for this smart tag.

The first of these is the namespace for this smart tag (contained in the @uri attribute). This allows the smart tag to specify a URI which should be round-tripped with this smart tag and be available to a consumer. It is intended to be used to specify a family of smart tags to which this one belongs – for example, in the sample above, the smart tag belongs to the http://schemas.openxmlformats.org/2006/smarttags namespace.

The second of these is the element name for this smart tag (contained in the @element attribute). This allows the smart tag to specify a name which should be round-tripped with this smart tag and again available to a consumer. It is intended to be used to specify a unique name for this type of smart tag – for example, in the sample above, the smart tag specifies that its data is of type stockticker.

As well as the required information specified above, a smart tag can also contain any number of additional properties in namespace/name/value sets by adding them to the smart tag’s property bag.

Using the example above, adding a new property called fullCompanyName with no namespace and value Microsoft Corporation to the smart tag would mean augmenting the output to add the <smartTagPr> element with this new property as follows:

  <w:smartTag w:uri="http://schemas.openxmlformats.org/2006/smarttags" 
     w:element="stockticker">
  <w:smartTagPr>
    <w:attr w:name="fullCompanyName" w:val="Microsoft Corporation"/>
  </w:smartTagPr>
  <w:r>
    <w:t>MSFT</w:t>
  </w:r>
</w:smartTag>

The resulting XML, as seen above, simply adds an <attr> element which specifies the property and value for the property bag.

A producer can embed a smart tag around any run-level content in a WordprocessingML document in order to embed additional information about the family and type of the data contained within. This allows ‘tagging’ of specific regions of a document with these semantics without need to provide context beyond the information provided in the @uri and @element attributes.

A consumer can read this smart tag data and provide additional functionality around these namespace/element pairs, which may or may not be specific to that smart tag type in the document. Examples of this functionality include: the ability to add/remove this markup via a user interface, ability to provide actions to operating in the context of this data type, etc.