Word.CustomXmlPart 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 a custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

Extends
OfficeExtension.ClientObject

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

id

Gets the ID of the custom XML part. Read only.

[ API set: WordApi BETA (PREVIEW ONLY) ]

namespaceUri

Gets the namespace URI of the custom XML part. Read only.

[ API set: WordApi BETA (PREVIEW ONLY) ]

Methods

delete()

Deletes the custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

deleteAttribute(xpath, namespaceMappings, name)

Deletes an attribute with the given name from the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

deleteElement(xpath, namespaceMappings)

Deletes the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

getXml()

Gets the full XML content of the custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

insertAttribute(xpath, namespaceMappings, name, value)

Inserts an attribute with the given name and value to the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

insertElement(xpath, xml, namespaceMappings, index)

Inserts the given XML under the parent element identified by xpath at child position index.

[ API set: WordApi BETA (PREVIEW ONLY) ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

query(xpath, namespaceMappings)

Queries the XML content of the custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

setXml(xml)

Sets the full XML content of the custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

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 is passed to it.) Whereas the original Word.CustomXmlPart object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.CustomXmlPartData) that contains shallow copies of any loaded child properties from the original object.

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 are 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 needed to have added the object to the tracked object collection when the object was first created.

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 will need to call "context.sync()" before the memory release takes effect.

updateAttribute(xpath, namespaceMappings, name, value)

Updates the value of an attribute with the given name of the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

updateElement(xpath, xml, namespaceMappings)

Updates the XML of the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

Property Details

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

id

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 ID of the custom XML part. Read only.

[ API set: WordApi BETA (PREVIEW ONLY) ]

readonly id: string;

Property Value

string

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 namespace URI of the custom XML part. Read only.

[ API set: WordApi BETA (PREVIEW ONLY) ]

readonly namespaceUri: string;

Property Value

string

Method Details

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 custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

delete(): void;

Returns

void

deleteAttribute(xpath, namespaceMappings, name)

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 an attribute with the given name from the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

deleteAttribute(xpath: string, namespaceMappings: any, name: string): void;

Parameters

xpath
string

Required. Absolute path to the single element in XPath notation.

namespaceMappings
any

Required. An object whose properties represent namespace aliases and the values are the actual namespace URIs.

name
string

Required. Name of the attribute.

Returns

void

deleteElement(xpath, namespaceMappings)

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 element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

deleteElement(xpath: string, namespaceMappings: any): void;

Parameters

xpath
string

Required. Absolute path to the single element in XPath notation.

namespaceMappings
any

Required. An object whose properties represent namespace aliases and the values are the actual namespace URIs.

Returns

void

getXml()

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 full XML content of the custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

getXml(): OfficeExtension.ClientResult<string>;

Returns

OfficeExtension.ClientResult<string>

insertAttribute(xpath, namespaceMappings, name, 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.

Inserts an attribute with the given name and value to the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

insertAttribute(xpath: string, namespaceMappings: any, name: string, value: string): void;

Parameters

xpath
string

Required. Absolute path to the single element in XPath notation.

namespaceMappings
any

Required. An object whose properties represent namespace aliases and the values are the actual namespace URIs.

name
string

Required. Name of the attribute.

value
string

Required. Value of the attribute.

Returns

void

insertElement(xpath, xml, namespaceMappings, index)

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 given XML under the parent element identified by xpath at child position index.

[ API set: WordApi BETA (PREVIEW ONLY) ]

insertElement(xpath: string, xml: string, namespaceMappings: any, index?: number): void;

Parameters

xpath
string

Required. Absolute path to the single parent element in XPath notation.

xml
string

Required. XML content to be inserted.

namespaceMappings
any

Required. An object whose properties represent namespace aliases and the values are the actual namespace URIs.

index
number

Optional. Zero-based position at which the new XML to be inserted. If omitted, the XML will be appended as the last child of this parent.

Returns

void

load(option)

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(option?: Word.Interfaces.CustomXmlPartLoadOptions): Word.CustomXmlPart;

Parameters

Returns

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Word.CustomXmlPart - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Word.CustomXmlPart - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Word.CustomXmlPart - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

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.CustomXmlPart;

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.CustomXmlPart;

Parameters

propertyNamesAndPaths
{ select?: string; expand?: string; }

Where 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

query(xpath, namespaceMappings)

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.

Queries the XML content of the custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

query(xpath: string, namespaceMappings: any): OfficeExtension.ClientResult<string[]>;

Parameters

xpath
string

Required. An XPath query.

namespaceMappings
any

Required. An object whose properties represent namespace aliases and the values are the actual namespace URIs.

Returns

OfficeExtension.ClientResult<string>[]

An array where each item represents an entry matched by the XPath query.

setXml(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.

Sets the full XML content of the custom XML part.

[ API set: WordApi BETA (PREVIEW ONLY) ]

setXml(xml: string): void;

Parameters

xml
string

Required. XML content to be set.

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 is passed to it.) Whereas the original Word.CustomXmlPart object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.CustomXmlPartData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Word.Interfaces.CustomXmlPartData;

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 are 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 needed to have added the object to the tracked object collection when the object was first created.

track(): Word.CustomXmlPart;

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 will need to call "context.sync()" before the memory release takes effect.

untrack(): Word.CustomXmlPart;

Returns

updateAttribute(xpath, namespaceMappings, name, 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.

Updates the value of an attribute with the given name of the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

updateAttribute(xpath: string, namespaceMappings: any, name: string, value: string): void;

Parameters

xpath
string

Required. Absolute path to the single element in XPath notation.

namespaceMappings
any

Required. An object whose properties represent namespace aliases and the values are the actual namespace URIs.

name
string

Required. Name of the attribute.

value
string

Required. New value of the attribute.

Returns

void

updateElement(xpath, xml, namespaceMappings)

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.

Updates the XML of the element identified by xpath.

[ API set: WordApi BETA (PREVIEW ONLY) ]

updateElement(xpath: string, xml: string, namespaceMappings: any): void;

Parameters

xpath
string

Required. Absolute path to the single element in XPath notation.

xml
string

Required. New XML content to be stored.

namespaceMappings
any

Required. An object whose properties represent namespace aliases and the values are the actual namespace URIs.

Returns

void