Office.CustomXmlParts interface

Represents a collection of CustomXmlPart objects.

Remarks

Applications: Word

Methods

addAsync(xml, options, callback)

Asynchronously adds a new custom XML part to a file.

addAsync(xml, callback)

Asynchronously adds a new custom XML part to a file.

getByIdAsync(id, options, callback)

Asynchronously gets the specified custom XML part by its ID.

getByIdAsync(id, callback)

Asynchronously gets the specified custom XML part by its ID.

getByNamespaceAsync(ns, options, callback)

Asynchronously gets the specified custom XML parts by its namespace.

getByNamespaceAsync(ns, callback)

Asynchronously gets the specified custom XML parts by its namespace.

Method Details

addAsync(xml, options, callback)

Asynchronously adds a new custom XML part to a file.

addAsync(xml: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<CustomXmlPart>) => void): void;

Parameters

xml

string

The XML to add to the newly created custom XML part.

options
Office.AsyncContextOptions

Provides an option for preserving context data of any type, unchanged, for use in a callback.

callback

(result: Office.AsyncResult<Office.CustomXmlPart>) => void

Optional. A function that is invoked when the callback returns, whose only parameter is of type Office.AsyncResult. The value property of the result is the newly created CustomXmlPart object.

Returns

void

Remarks

Requirement set: CustomXmlParts

addAsync(xml, callback)

Asynchronously adds a new custom XML part to a file.

addAsync(xml: string, callback?: (result: AsyncResult<CustomXmlPart>) => void): void;

Parameters

xml

string

The XML to add to the newly created custom XML part.

callback

(result: Office.AsyncResult<Office.CustomXmlPart>) => void

Optional. A function that is invoked when the callback returns, whose only parameter is of type Office.AsyncResult. The value property of the result is the newly created CustomXmlPart object.

Returns

void

Remarks

Requirement set: CustomXmlParts

Examples

function addXMLPart() {
    Office.context.document.customXmlParts.addAsync(
        '<root categoryId="1" xmlns="http://tempuri.org"><item name="Cheap Item" price="$193.95"/><item name="Expensive Item" price="$931.88"/></root>',
        function (result) {});
}

function addXMLPartandHandler() {
    Office.context.document.customXmlParts.addAsync(
        "<testns:book xmlns:testns='http://testns.com'><testns:page number='1'>Hello</testns:page><testns:page number='2'>world!</testns:page></testns:book>",
        function(r) { r.value.addHandlerAsync(Office.EventType.DataNodeDeleted,
            function(a) {write(a.type)
            },
                function(s) {write(s.status)
                });
        });
}

// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message;
}

getByIdAsync(id, options, callback)

Asynchronously gets the specified custom XML part by its ID.

getByIdAsync(id: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<CustomXmlPart>) => void): void;

Parameters

id

string

The GUID of the custom XML part, including opening and closing braces.

options
Office.AsyncContextOptions

Provides an option for preserving context data of any type, unchanged, for use in a callback.

callback

(result: Office.AsyncResult<Office.CustomXmlPart>) => void

Optional. A function that is invoked when the callback returns, whose only parameter is of type Office.AsyncResult. The value property of the result is a CustomXmlPart object that represents the specified custom XML part. If there is no custom XML part with the specified ID, the method returns null.

Returns

void

Remarks

Requirement set: CustomXmlParts

Examples

function showXMLPartInnerXML() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getXmlAsync({}, function (eventArgs) {
            write(eventArgs.value);
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

getByIdAsync(id, callback)

Asynchronously gets the specified custom XML part by its ID.

getByIdAsync(id: string, callback?: (result: AsyncResult<CustomXmlPart>) => void): void;

Parameters

id

string

The GUID of the custom XML part, including opening and closing braces.

callback

(result: Office.AsyncResult<Office.CustomXmlPart>) => void

Optional. A function that is invoked when the callback returns, whose only parameter is of type Office.AsyncResult. The value property of the result is a CustomXmlPart object that represents the specified custom XML part. If there is no custom XML part with the specified ID, the method returns null.

Returns

void

Remarks

Requirement set: CustomXmlParts

getByNamespaceAsync(ns, options, callback)

Asynchronously gets the specified custom XML parts by its namespace.

getByNamespaceAsync(ns: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<CustomXmlPart[]>) => void): void;

Parameters

ns

string

The namespace URI.

options
Office.AsyncContextOptions

Provides an option for preserving context data of any type, unchanged, for use in a callback.

callback

(result: Office.AsyncResult<Office.CustomXmlPart[]>) => void

Optional. A function that is invoked when the callback returns, whose only parameter is of type Office.AsyncResult. The value property of the result is an array of CustomXmlPart objects that match the specified namespace.

Returns

void

Remarks

Requirement set: CustomXmlParts

getByNamespaceAsync(ns, callback)

Asynchronously gets the specified custom XML parts by its namespace.

getByNamespaceAsync(ns: string, callback?: (result: AsyncResult<CustomXmlPart[]>) => void): void;

Parameters

ns

string

The namespace URI.

callback

(result: Office.AsyncResult<Office.CustomXmlPart[]>) => void

Optional. A function that is invoked when the callback returns, whose only parameter is of type Office.AsyncResult. The value property of the result is an array of CustomXmlPart objects that match the specified namespace.

Returns

void

Remarks

Requirement set: CustomXmlParts

Examples

function showXMLPartsInNamespace() {
    Office.context.document.customXmlParts.getByNamespaceAsync(
        "http://tempuri.org", 
        function (eventArgs) {
            write("Found " + eventArgs.value.length + " parts with this namespace");
    }); 
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}