w:tag (Structured Document Tag Programmatic Tag)
Provides a programmatic identifier for a structured document tag, used by code to locate or process the SDT independently of its display name.
Parent elements
Description
w:tag stores a programmatic string identifier for an SDT. Unlike w:alias (which is a user-visible display name), w:tag is intended for use by code — for example, to find all content controls with a specific tag and populate them with data.
It is defined in ECMA-376 Part 1 §17.5.2.40.
Tag values are arbitrary strings and need not be unique in a document, though uniqueness is often desirable in practice.
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
w:val |
xsd:string |
Any string | Programmatic identifier for the SDT. |
Examples
<w:sdtPr>
<w:alias w:val="Invoice Date"/>
<w:tag w:val="invoiceDate"/>
<w:date/>
</w:sdtPr>
using DocumentFormat.OpenXml.Wordprocessing;
using System.Linq;
// Set a tag on an SDT
var sdtPr = new SdtProperties(
new SdtAlias { Val = "Invoice Date" },
new Tag { Val = "invoiceDate" },
new SdtDate()
);
// Find all SDTs with a specific tag
var controls = document.Body
.Descendants<SdtElement>()
.Where(sdt => sdt.SdtProperties?
.Descendants<Tag>()
.FirstOrDefault()?.Val == "invoiceDate");
Notes
w:tagcorresponds to the “Tag” field in the Content Control Properties dialog in Word.- When using data binding via
w:dataBinding, the tag is often used in conjunction with XPath expressions for disambiguation.