Word.XmlNode class
Represents a single XML node applied to the document.
- Extends
Remarks
Properties
| attributes | Gets the attributes for this XML node. Returns |
| base |
Gets the name of the element without any prefix. |
| child |
Gets the child elements of this XML node. Returns an empty collection if the node type is |
| context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
| first |
Gets the first child node if this is a parent node. Returns |
| has |
Gets whether this XML node has child nodes. Always returns |
| last |
Gets the last child node if this is a parent node. Returns |
| level | Gets whether this XML element is part of a paragraph, is a paragraph, or is contained within a table cell or contains a table row. Returns |
| namespace |
Gets the Uniform Resource Identifier (URI) of the schema namespace for this XML node. |
| next |
Gets the next element in the document that's at the same level as this XML node. Returns |
| owner |
Gets the parent document of this XML node. |
| parent |
Gets the parent element of this XML node. |
| placeholder |
Specifies the text displayed for this element if it contains no text. Only applies to element nodes, not attribute nodes. |
| previous |
Gets the previous element in the document that's at the same level as this XML node. Returns |
| range | Gets the portion of a document that is contained in this XML node. Returns |
| text | Specifies the text contained within the XML element. Returns an empty string if the node type is |
| type | Gets the type of node. |
| validation |
Gets the description for a validation error on this |
| validation |
Gets whether this element is valid according to the attached schema. May not be meaningful for attribute nodes. |
| value | Specifies the value of this XML node. For element nodes, represents the text content; for attribute nodes, represents the attribute value. |
Methods
| copy() | Copies this XML node, excluding XML markup, to the Clipboard. For attribute nodes, copies only the attribute value as text. |
| cut() | Removes this XML node from the document and places it on the Clipboard. For attribute nodes, removes the attribute from its parent element and copies only the attribute value as text to the clipboard. |
| delete() | Deletes the XML node from the XML document. For element nodes, removes the entire element and its content; for attribute nodes, removes the attribute from its parent element. |
| load(options) | Queues up a command to load the specified properties of the object. You must call |
| load(property |
Queues up a command to load the specified properties of the object. You must call |
| load(property |
Queues up a command to load the specified properties of the object. You must call |
| remove |
Removes a child element from this XML node. This method has no effect if the node type is |
| select |
Returns all the child elements that match the XPath parameter, in the order in which they appear within this XML node. Returns |
| select |
Returns the first child element that matches the XPath parameter within this XML node. Returns |
| set |
Changes the validation error text displayed to a user for this XML node and whether to force Word to report the node as invalid. May not be meaningful for attribute nodes. |
| set |
Changes the validation error text displayed to a user for this XML node and whether to force Word to report the node as invalid. May not be meaningful for attribute nodes. |
| toJSON() | Overrides the JavaScript |
| track() | Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across |
| untrack() | Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call |
| validate() | Validates this XML node against the XML schemas that are attached to the document. May not be meaningful for attribute nodes. |
Property Details
attributes
Gets the attributes for this XML node. Returns null if the node type is attribute.
readonly attributes: Word.XmlNodeCollection;
Property Value
Remarks
baseName
Gets the name of the element without any prefix.
readonly baseName: string;
Property Value
string
Remarks
childNodes
Gets the child elements of this XML node. Returns an empty collection if the node type is attribute.
readonly childNodes: Word.XmlNodeCollection;
Property Value
Remarks
context
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
firstChild
Gets the first child node if this is a parent node. Returns null if the node type is attribute.
readonly firstChild: Word.XmlNode;
Property Value
Remarks
hasChildNodes
Gets whether this XML node has child nodes. Always returns false for attribute nodes since they cannot have children.
readonly hasChildNodes: boolean;
Property Value
boolean
Remarks
lastChild
Gets the last child node if this is a parent node. Returns null if the node type is attribute.
readonly lastChild: Word.XmlNode;
Property Value
Remarks
level
Gets whether this XML element is part of a paragraph, is a paragraph, or is contained within a table cell or contains a table row. Returns null if the node type is attribute.
readonly level: Word.XmlNodeLevel | "Inline" | "Paragraph" | "Row" | "Cell";
Property Value
Word.XmlNodeLevel | "Inline" | "Paragraph" | "Row" | "Cell"
Remarks
namespaceUri
Gets the Uniform Resource Identifier (URI) of the schema namespace for this XML node.
readonly namespaceUri: string;
Property Value
string
Remarks
nextSibling
Gets the next element in the document that's at the same level as this XML node. Returns null if the node type is attribute.
readonly nextSibling: Word.XmlNode;
Property Value
Remarks
ownerDocument
Gets the parent document of this XML node.
readonly ownerDocument: Word.Document;
Property Value
Remarks
parentNode
Gets the parent element of this XML node.
readonly parentNode: Word.XmlNode;
Property Value
Remarks
placeholderText
Specifies the text displayed for this element if it contains no text. Only applies to element nodes, not attribute nodes.
placeholderText: string;
Property Value
string
Remarks
previousSibling
Gets the previous element in the document that's at the same level as this XML node. Returns null if the node type is attribute.
readonly previousSibling: Word.XmlNode;
Property Value
Remarks
range
Gets the portion of a document that is contained in this XML node. Returns null if the node type is attribute.
readonly range: Word.Range;
Property Value
Remarks
text
Specifies the text contained within the XML element. Returns an empty string if the node type is attribute.
text: string;
Property Value
string
Remarks
type
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Gets the type of node.
readonly type: Word.XmlNodeType | "Element" | "Attribute";
Property Value
Word.XmlNodeType | "Element" | "Attribute"
Remarks
validationErrorText
Gets the description for a validation error on this XmlNode object. May not be meaningful for attribute nodes.
readonly validationErrorText: string;
Property Value
string
Remarks
validationStatus
Gets whether this element is valid according to the attached schema. May not be meaningful for attribute nodes.
readonly validationStatus: Word.XmlValidationStatus | "Ok" | "Custom";
Property Value
Word.XmlValidationStatus | "Ok" | "Custom"
Remarks
value
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Specifies the value of this XML node. For element nodes, represents the text content; for attribute nodes, represents the attribute value.
value: string;
Property Value
string
Remarks
Method Details
copy()
Copies this XML node, excluding XML markup, to the Clipboard. For attribute nodes, copies only the attribute value as text.
copy(): void;
Returns
void
Remarks
cut()
Removes this XML node from the document and places it on the Clipboard. For attribute nodes, removes the attribute from its parent element and copies only the attribute value as text to the clipboard.
cut(): void;
Returns
void
Remarks
delete()
Deletes the XML node from the XML document. For element nodes, removes the entire element and its content; for attribute nodes, removes the attribute from its parent element.
delete(): void;
Returns
void
Remarks
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(options?: Word.Interfaces.XmlNodeLoadOptions): Word.XmlNode;
Parameters
Provides options for which properties of the object to load.
Returns
load(propertyNames)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(propertyNames?: string | string[]): Word.XmlNode;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
load(propertyNamesAndPaths)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.XmlNode;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.
Returns
removeChild(childElement)
Removes a child element from this XML node. This method has no effect if the node type is attribute (since attribute nodes have no child elements).
removeChild(childElement: Word.XmlNode): void;
Parameters
- childElement
- Word.XmlNode
The child element to remove.
Returns
void
Remarks
selectNodes(xPath, options)
Returns all the child elements that match the XPath parameter, in the order in which they appear within this XML node. Returns null if the node type is attribute (since attribute nodes have no child elements to search).
selectNodes(xPath: string, options?: Word.SelectNodesOptions): Word.XmlNodeCollection;
Parameters
- xPath
-
string
The XPath expression to evaluate.
- options
- Word.SelectNodesOptions
Optional. Configuration options for the XPath search.
Returns
A collection of XML nodes that match the XPath expression.
Remarks
selectSingleNode(xPath, options)
Returns the first child element that matches the XPath parameter within this XML node. Returns null if the node type is attribute (since attribute nodes have no child elements to search).
selectSingleNode(xPath: string, options?: Word.SelectSingleNodeOptions): Word.XmlNode;
Parameters
- xPath
-
string
The XPath expression to evaluate.
- options
- Word.SelectSingleNodeOptions
Optional. Configuration options for the XPath search.
Returns
The first XML node that matches the XPath expression, or null if no match is found.
Remarks
setValidationError(status, options)
Changes the validation error text displayed to a user for this XML node and whether to force Word to report the node as invalid. May not be meaningful for attribute nodes.
setValidationError(status: Word.XmlValidationStatus, options?: Word.XmlNodeSetValidationErrorOptions): void;
Parameters
- status
- Word.XmlValidationStatus
The validation status to set.
Optional. Configuration options for setting the validation error.
Returns
void
Remarks
setValidationError(status, options)
Changes the validation error text displayed to a user for this XML node and whether to force Word to report the node as invalid. May not be meaningful for attribute nodes.
setValidationError(status: "Ok" | "Custom", options?: Word.XmlNodeSetValidationErrorOptions): void;
Parameters
- status
-
"Ok" | "Custom"
The validation status to set.
Optional. Configuration options for setting the validation error.
Returns
void
Remarks
toJSON()
Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original Word.XmlNode object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.XmlNodeData) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Word.Interfaces.XmlNodeData;
Returns
track()
Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.
track(): Word.XmlNode;
Returns
untrack()
Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call context.sync() before the memory release takes effect.
untrack(): Word.XmlNode;
Returns
validate()
Validates this XML node against the XML schemas that are attached to the document. May not be meaningful for attribute nodes.
validate(): void;
Returns
void