CustomXmlProperty class

CustomXmlProperty class

Represents a single custom XML attribute or a smart tag property. To learn more, visit the Structured Document Tags or Content Control documentation article.

Remarks

Used as an item of a CustomXmlPropertyCollection collection.

Constructors

NameDescription
CustomXmlProperty(name, uri, value)Initializes a new instance of this class.

Properties

NameDescription
nameSpecifies the name of the custom XML attribute or smart tag property.
uriGets or sets the namespace URI of the custom XML attribute or smart tag property.
valueGets or sets the value of the custom XML attribute or smart tag property.

Examples

Shows how to create smart tags.

def create():
    doc = aw.Document()
    # A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
    # such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
    smart_tag = aw.markup.SmartTag(doc)
    # Smart tags are composite nodes that contain their recognized text in its entirety.
    # Add contents to this smart tag manually.
    smart_tag.append_child(aw.Run(doc, 'May 29, 2019'))
    # Microsoft Word may recognize the above contents as being a date.
    # Smart tags use the "Element" property to reflect the type of data they contain.
    smart_tag.element = 'date'
    # Some smart tag types process their contents further into custom XML properties.
    smart_tag.properties.add(aw.markup.CustomXmlProperty('Day', '', '29'))
    smart_tag.properties.add(aw.markup.CustomXmlProperty('Month', '', '5'))
    smart_tag.properties.add(aw.markup.CustomXmlProperty('Year', '', '2019'))
    # Set the smart tag's URI to the default value.
    smart_tag.uri = 'urn:schemas-microsoft-com:office:smarttags'
    doc.first_section.body.first_paragraph.append_child(smart_tag)
    doc.first_section.body.first_paragraph.append_child(aw.Run(doc, ' is a date. '))
    # Create another smart tag for a stock ticker.
    smart_tag = aw.markup.SmartTag(doc)
    smart_tag.element = 'stockticker'
    smart_tag.uri = 'urn:schemas-microsoft-com:office:smarttags'
    smart_tag.append_child(aw.Run(doc, 'MSFT'))
    doc.first_section.body.first_paragraph.append_child(smart_tag)
    doc.first_section.body.first_paragraph.append_child(aw.Run(doc, ' is a stock ticker.'))
    # Older versions of Microsoft Word support smart tags.
    doc.save(ARTIFACTS_DIR + 'SmartTag.create.doc')
    # Use the "remove_smart_tags" method to remove all smart tags from a document.
    self.assertEqual(2, doc.get_child_nodes(aw.NodeType.SMART_TAG, True).count)
    doc.remove_smart_tags()
    self.assertEqual(0, doc.get_child_nodes(aw.NodeType.SMART_TAG, True).count)

See Also