w:t (Text Content)
Contains the literal character data of a run. Use xml:space='preserve' when leading or trailing spaces are significant.
Parent elements
Description
w:t holds the literal text content of a run. It is defined in ECMA-376 Part 1 §17.3.3.31.
By default, XML parsers strip leading and trailing whitespace from element content. To preserve spaces at the start or end of the text node, set the standard XML attribute xml:space="preserve". This is important when the text is part of a word boundary that spans multiple runs.
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
xml:space |
XML standard | preserve (keep leading/trailing spaces) or default (XML default — spaces may be collapsed). |
Controls whitespace handling for the text content. |
Examples
Plain text
<w:t>Hello</w:t>
new Text("Hello");
Text with preserved leading space
<w:t xml:space="preserve"> world</w:t>
new Text(" world") { Space = SpaceProcessingModeValues.Preserve };
Notes
- Always use
xml:space="preserve"when the text begins or ends with a space character, otherwise the space will be lost during XML parsing. w:tcan only appear insidew:r; it must not span run or paragraph boundaries.