Word.CustomXmlNode class
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.
Represents an XML node in a tree in the document. The CustomXmlNode
object is a member of the Word.CustomXmlNodeCollection object.
- Extends
Remarks
Properties
attributes | Gets a |
base |
Gets the base name of the node without the namespace prefix, if one exists. |
child |
Gets a |
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
first |
Gets a |
last |
Gets a |
namespace |
Gets the unique address identifier for the namespace of the node. |
next |
Gets the next sibling node (element, comment, or processing instruction) of the current node. If the node is the last sibling at its level, the property returns |
node |
Gets the type of the current node. |
node |
Specifies the value of the current node. |
owner |
Gets the object representing the part associated with this node. |
parent |
Gets the parent element node of the current node. If the current node is at the root level, the property returns |
previous |
Gets the previous sibling node (element, comment, or processing instruction) of the current node. If the current node is the first sibling at its level, the property returns |
text | Specifies the text for the current node. |
xml | Gets the XML representation of the current node and its children. |
xpath | Gets a string with the canonicalized XPath for the current node. If the node is no longer in the Document Object Model (DOM), the property returns an error message. |
Methods
append |
Appends a single node as the last child under the context element node in the tree. |
append |
Adds a subtree as the last child under the context element node in the tree. |
delete() | Deletes the current node from the tree (including all of its children, if any exist). |
has |
Specifies if the current element node has child element nodes. |
insert |
Inserts a new node just before the context node in the tree. |
insert |
Inserts the specified subtree into the location just before the context node. |
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 the specified child node from the tree. |
replace |
Removes the specified child node and replaces it with a different node in the same location. |
replace |
Removes the specified node and replaces it with a different subtree in the same location. |
select |
Selects a collection of nodes matching an XPath expression. |
select |
Selects a single node from a collection matching an XPath expression. |
set(properties, options) | Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type. |
set(properties) | Sets multiple properties on the object at the same time, based on an existing loaded object. |
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 |
Property Details
attributes
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 a CustomXmlNodeCollection
object representing the attributes of the current element in the current node.
readonly attributes: Word.CustomXmlNodeCollection;
Property Value
Remarks
baseName
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 base name of the node without the namespace prefix, if one exists.
readonly baseName: string;
Property Value
string
Remarks
childNodes
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 a CustomXmlNodeCollection
object containing all of the child elements of the current node.
readonly childNodes: Word.CustomXmlNodeCollection;
Property Value
Remarks
context
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.
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
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 a CustomXmlNode
object corresponding to the first child element of the current node. If the node has no child elements (or if it isn't of type CustomXmlNodeType.element), returns Nothing
.
readonly firstChild: Word.CustomXmlNode;
Property Value
Remarks
lastChild
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 a CustomXmlNode
object corresponding to the last child element of the current node. If the node has no child elements (or if it isn't of type CustomXmlNodeType.element), the property returns Nothing
.
readonly lastChild: Word.CustomXmlNode;
Property Value
Remarks
namespaceUri
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 unique address identifier for the namespace of the node.
readonly namespaceUri: string;
Property Value
string
Remarks
nextSibling
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 next sibling node (element, comment, or processing instruction) of the current node. If the node is the last sibling at its level, the property returns Nothing
.
readonly nextSibling: Word.CustomXmlNode;
Property Value
Remarks
nodeType
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 the current node.
readonly nodeType: Word.CustomXmlNodeType | "element" | "attribute" | "text" | "cData" | "processingInstruction" | "comment" | "document";
Property Value
Word.CustomXmlNodeType | "element" | "attribute" | "text" | "cData" | "processingInstruction" | "comment" | "document"
Remarks
nodeValue
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 the current node.
nodeValue: string;
Property Value
string
Remarks
ownerPart
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 object representing the part associated with this node.
readonly ownerPart: Word.CustomXmlPart;
Property Value
Remarks
parentNode
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 parent element node of the current node. If the current node is at the root level, the property returns Nothing
.
readonly parentNode: Word.CustomXmlNode;
Property Value
Remarks
previousSibling
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 previous sibling node (element, comment, or processing instruction) of the current node. If the current node is the first sibling at its level, the property returns Nothing
.
readonly previousSibling: Word.CustomXmlNode;
Property Value
Remarks
text
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 text for the current node.
text: string;
Property Value
string
Remarks
xml
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 XML representation of the current node and its children.
readonly xml: string;
Property Value
string
Remarks
xpath
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 a string with the canonicalized XPath for the current node. If the node is no longer in the Document Object Model (DOM), the property returns an error message.
readonly xpath: string;
Property Value
string
Remarks
Method Details
appendChildNode(options)
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.
Appends a single node as the last child under the context element node in the tree.
appendChildNode(options?: Word.CustomXmlAppendChildNodeOptions): OfficeExtension.ClientResult<number>;
Parameters
Optional. The options that define the node to be appended.
Returns
OfficeExtension.ClientResult<number>
Remarks
appendChildSubtree(xml)
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.
Adds a subtree as the last child under the context element node in the tree.
appendChildSubtree(xml: string): OfficeExtension.ClientResult<number>;
Parameters
- xml
-
string
A string representing the XML subtree.
Returns
OfficeExtension.ClientResult<number>
Remarks
delete()
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.
Deletes the current node from the tree (including all of its children, if any exist).
delete(): void;
Returns
void
Remarks
hasChildNodes()
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 if the current element node has child element nodes.
hasChildNodes(): OfficeExtension.ClientResult<boolean>;
Returns
OfficeExtension.ClientResult<boolean>
Remarks
insertNodeBefore(options)
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.
Inserts a new node just before the context node in the tree.
insertNodeBefore(options?: Word.CustomXmlInsertNodeBeforeOptions): OfficeExtension.ClientResult<number>;
Parameters
Optional. The options that define the node to be inserted.
Returns
OfficeExtension.ClientResult<number>
Remarks
insertSubtreeBefore(xml, options)
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.
Inserts the specified subtree into the location just before the context node.
insertSubtreeBefore(xml: string, options?: Word.CustomXmlInsertSubtreeBeforeOptions): OfficeExtension.ClientResult<number>;
Parameters
- xml
-
string
A string representing the XML subtree.
Optional. The options available for inserting the subtree.
Returns
OfficeExtension.ClientResult<number>
Remarks
load(options)
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.
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.CustomXmlNodeLoadOptions): Word.CustomXmlNode;
Parameters
Provides options for which properties of the object to load.
Returns
load(propertyNames)
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.
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.CustomXmlNode;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
load(propertyNamesAndPaths)
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.
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.CustomXmlNode;
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(child)
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.
Removes the specified child node from the tree.
removeChild(child: Word.CustomXmlNode): OfficeExtension.ClientResult<number>;
Parameters
- child
- Word.CustomXmlNode
The child node to remove.
Returns
OfficeExtension.ClientResult<number>
Remarks
replaceChildNode(oldNode, options)
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.
Removes the specified child node and replaces it with a different node in the same location.
replaceChildNode(oldNode: Word.CustomXmlNode, options?: Word.CustomXmlReplaceChildNodeOptions): OfficeExtension.ClientResult<number>;
Parameters
- oldNode
- Word.CustomXmlNode
The node to be replaced.
Optional. The options that define the child node which is to replace the old node.
Returns
OfficeExtension.ClientResult<number>
Remarks
replaceChildSubtree(xml, oldNode)
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.
Removes the specified node and replaces it with a different subtree in the same location.
replaceChildSubtree(xml: string, oldNode: Word.CustomXmlNode): OfficeExtension.ClientResult<number>;
Parameters
- xml
-
string
A string representing the new subtree.
- oldNode
- Word.CustomXmlNode
The node to be replaced.
Returns
OfficeExtension.ClientResult<number>
Remarks
selectNodes(xPath)
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.
Selects a collection of nodes matching an XPath expression.
selectNodes(xPath: string): Word.CustomXmlNodeCollection;
Parameters
- xPath
-
string
The XPath expression.
Returns
Remarks
selectSingleNode(xPath)
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.
Selects a single node from a collection matching an XPath expression.
selectSingleNode(xPath: string): Word.CustomXmlNode;
Parameters
- xPath
-
string
The XPath expression.
Returns
Remarks
set(properties, options)
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.
Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.
set(properties: Interfaces.CustomXmlNodeUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Word.Interfaces.CustomXmlNodeUpdateData
A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.
- options
- OfficeExtension.UpdateOptions
Provides an option to suppress errors if the properties object tries to set any read-only properties.
Returns
void
set(properties)
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.
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: Word.CustomXmlNode): void;
Parameters
- properties
- Word.CustomXmlNode
Returns
void
toJSON()
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.
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.CustomXmlNode
object is an API object, the toJSON
method returns a plain JavaScript object (typed as Word.Interfaces.CustomXmlNodeData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Word.Interfaces.CustomXmlNodeData;
Returns
track()
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.
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.CustomXmlNode;
Returns
untrack()
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.
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.CustomXmlNode;