Office.CustomXmlNode interface

ドキュメント内のツリーの XML ノードを表します。

注釈

アプリケーション: Word

プロパティ

baseName

名前空間プレフィックスを持たないノードがある場合、そのベース名を取得します。

namespaceUri

CustomXMLPart の文字列 GUID を取得します。

nodeType

CustomXMLNode の型を取得します。

メソッド

getNodesAsync(xPath, options, callback)

XPath 式に関連付けられているノードを取得します。

getNodesAsync(xPath, callback)

XPath 式に関連付けられているノードを取得します。

getNodeValueAsync(options, callback)

ノード値を取得します。

getNodeValueAsync(callback)

ノード値を取得します。

getTextAsync(options, callback)

カスタム XML パーツ内の XML ノードのテキストを取得します。

getTextAsync(callback)

カスタム XML パーツ内の XML ノードのテキストを取得します。

getXmlAsync(options, callback)

ノードの XML を取得します。

getXmlAsync(callback)

ノードの XML を取得します。

setNodeValueAsync(value, options, callback)

ノード値を設定します。

setNodeValueAsync(value, callback)

ノード値を設定します。

setTextAsync(text, options, callback)

カスタム XML パーツ内の XML ノードのテキストを非同期的に設定します。

setTextAsync(text, callback)

カスタム XML パーツ内の XML ノードのテキストを非同期的に設定します。

setXmlAsync(xml, options, callback)

ノード XML を設定します。

setXmlAsync(xml, callback)

ノード XML を設定します。

プロパティの詳細

baseName

名前空間プレフィックスを持たないノードがある場合、そのベース名を取得します。

baseName: string;

プロパティ値

string

function showXmlNodeBaseNames() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getNodesAsync('*/*', function (nodeResults) {
            for (let i = 0; i < nodeResults.value.length; i++) {
                const node = nodeResults.value[i];
                write(node.baseName);
            }
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

namespaceUri

CustomXMLPart の文字列 GUID を取得します。

namespaceUri: string;

プロパティ値

string

function showXmlNamespaceUri() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getNodesAsync('*/*', function (nodeResults) {
            for (let i = 0; i < nodeResults.value.length; i++) {
                const node = nodeResults.value[i];
                write(node.namespaceUri);
            }
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

nodeType

CustomXMLNode の型を取得します。

nodeType: string;

プロパティ値

string

function showXmlNodeType() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getNodesAsync('*/*', function (nodeResults) {
            for (let i = 0; i < nodeResults.value.length; i++) {
                const node = nodeResults.value[i];
                write(node.nodeType);
            }
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

メソッドの詳細

getNodesAsync(xPath, options, callback)

XPath 式に関連付けられているノードを取得します。

getNodesAsync(xPath: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<CustomXmlNode[]>) => void): void;

パラメーター

xPath

string

取得するノードを指定する XPath 式。 必須です。

options
Office.AsyncContextOptions

コールバックで使用するために、任意の型のコンテキスト データを変更せずに保持するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、パラメーターに渡される XPath 式で指定されたノードを表す CustomXmlNode オブジェクトの xPath 配列です。

戻り値

void

注釈

要件セット: CustomXmlParts

getNodesAsync(xPath, callback)

XPath 式に関連付けられているノードを取得します。

getNodesAsync(xPath: string, callback?: (result: AsyncResult<CustomXmlNode[]>) => void): void;

パラメーター

xPath

string

取得するノードを指定する XPath 式。 必須です。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、パラメーターに渡される XPath 式で指定されたノードを表す CustomXmlNode オブジェクトの xPath 配列です。

戻り値

void

注釈

要件セット: CustomXmlParts

function showXmlChildNodes() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getNodesAsync('*', function (nodeResults) {
            for (let i = 0; i < nodeResults.value.length; i++) {
                const node = nodeResults.value[i];
                node.getNodesAsync('*', function (nodeResults) {
                    write(nodeResults.value.length + " childNodes");
                });
            }
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

getNodeValueAsync(options, callback)

ノード値を取得します。

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

パラメーター

options
Office.AsyncContextOptions

コールバックで使用するために、任意の型のコンテキスト データを変更せずに保持するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果の プロパティは value 、参照先ノードの値を含む文字列です。

戻り値

void

注釈

要件セット: CustomXmlParts

getNodeValueAsync(callback)

ノード値を取得します。

getNodeValueAsync(callback?: (result: AsyncResult<string>) => void): void;

パラメーター

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果の プロパティは value 、参照先ノードの値を含む文字列です。

戻り値

void

注釈

要件セット: CustomXmlParts

function showXmlNodeValues() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getNodesAsync('*/*', function (nodeResults) {
            for (let i = 0; i < nodeResults.value.length; i++) {
                const node = nodeResults.value[i];
                node.getNodeValueAsync(function (asyncResult) {
                    write(asyncResult.value);
                });
            }
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

getTextAsync(options, callback)

カスタム XML パーツ内の XML ノードのテキストを取得します。

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

パラメーター

options
Office.AsyncContextOptions

コールバックで使用するために、任意の型のコンテキスト データを変更せずに保持するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果の プロパティは value 、参照先ノードの内部テキストを含む文字列です。

戻り値

void

注釈

要件セット: CustomXmlParts

// Get the built-in core properties XML part by using its ID. This results in a call to Word.
Office.context.document.customXmlParts.getByIdAsync(
    "{6C3C8BC8-F283-45AE-878A-BAB7291924A1}", function (getByIdAsyncResult) {
    
    // Access the XML part.
    const xmlPart = getByIdAsyncResult.value;
    
    // Add namespaces to the namespace manager. These two calls result in two calls to Word.
    xmlPart.namespaceManager.addNamespaceAsync(
        'cp',
        'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
        function () {
        xmlPart.namespaceManager.addNamespaceAsync(
            'dc', 
            'http://purl.org/dc/elements/1.1/', 
            function () {

            // Get XML nodes by using an Xpath expression. This results in a call to Word.
            xmlPart.getNodesAsync("/cp:coreProperties/dc:title", function (getNodesAsyncResult) {
                
                // Get the first node returned by using the Xpath expression. 
                const node = getNodesAsyncResult.value[0];
                
                // Get the text value of the node and use the asyncContext. This results in a call to Word. 
                // The results are logged to the browser console.
                node.getTextAsync({asyncContext: "StateNormal"}, function (getTextAsyncResult) {
                  console.log("Text of the title element = " + getTextAsyncResult.value;
                  console.log("The asyncContext value = " + getTextAsyncResult.asyncContext;
                });
            });
        });
    });
});

getTextAsync(callback)

カスタム XML パーツ内の XML ノードのテキストを取得します。

getTextAsync(callback?: (result: AsyncResult<string>) => void): void;

パラメーター

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果の プロパティは value 、参照先ノードの内部テキストを含む文字列です。

戻り値

void

注釈

要件セット: CustomXmlParts

getXmlAsync(options, callback)

ノードの XML を取得します。

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

パラメーター

options
Office.AsyncContextOptions

コールバックで使用するために、任意の型のコンテキスト データを変更せずに保持するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果の プロパティは value 、参照先ノードの XML を含む文字列です。

戻り値

void

注釈

要件セット: CustomXmlParts

getXmlAsync(callback)

ノードの XML を取得します。

getXmlAsync(callback?: (result: AsyncResult<string>) => void): void;

パラメーター

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果の プロパティは value 、参照先ノードの XML を含む文字列です。

戻り値

void

注釈

要件セット: CustomXmlParts

function showXmlNodeInnerXml() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getNodesAsync('*', function (nodeResults) {
            for (let i = 0; i < nodeResults.value.length; i++) {
                const node = nodeResults.value[i];
                node.getXmlAsync(function (asyncResult) {
                    write(asyncResult.value);
                });
            }
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

setNodeValueAsync(value, options, callback)

ノード値を設定します。

setNodeValueAsync(value: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

value

string

ノードに設定する値

options
Office.AsyncContextOptions

コールバックで使用するために、任意の型のコンテキスト データを変更せずに保持するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。

戻り値

void

注釈

要件セット: CustomXmlParts

setNodeValueAsync(value, callback)

ノード値を設定します。

setNodeValueAsync(value: string, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

value

string

ノードに設定する値

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。

戻り値

void

注釈

要件セット: CustomXmlParts

function setXmlNodeValue() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getNodesAsync('*/*', function (nodeResults) {
            for (let i = 0; i < nodeResults.value.length; i++) {
                const node = nodeResults.value[i];
                write(node);
                node.setNodeValueAsync("item number" + i, function (result) { });
            }
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

setTextAsync(text, options, callback)

カスタム XML パーツ内の XML ノードのテキストを非同期的に設定します。

setTextAsync(text: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

text

string

必須です。 XML ノードのテキスト値。

options
Office.AsyncContextOptions

コールバックで使用するために、任意の型のコンテキスト データを変更せずに保持するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。

戻り値

void

注釈

要件セット: CustomXmlParts

// Learn how to set the text value of a node in a custom XML part from the following example.

// Get the built-in core properties XML part by using its ID. This results in a call to Word.
Office.context.document.customXmlParts.getByIdAsync(
    "{6C3C8BC8-F283-45AE-878A-BAB7291924A1}",
    function (getByIdAsyncResult) {
    
    // Access the XML part.
    const xmlPart = getByIdAsyncResult.value;
    
    // Add namespaces to the namespace manager. These two calls result in two calls to Word.
    xmlPart.namespaceManager.addNamespaceAsync(
        'cp', 
        'http://schemas.openxmlformats.org/package/2006/metadata/core-properties', 
        function () {
        xmlPart.namespaceManager.addNamespaceAsync(
            'dc', 
            'http://purl.org/dc/elements/1.1/', 
            function () {

            // Get XML nodes by using an Xpath expression. This results in a call to the host.
            xmlPart.getNodesAsync("/cp:coreProperties/dc:subject", function (getNodesAsyncResult) {
                
                // Get the first node returned by using the Xpath expression.
                // This will be the subject element in this example.
                const subjectNode = getNodesAsyncResult.value[0];
                
                // Set the text value of the subject node and use the asyncContext. 
                // This results in a call to the host.  The results are logged to the browser console.
                subjectNode.setTextAsync(
                    "newSubject", 
                    {asyncContext: "StateNormal"}, 
                    function (setTextAsyncResult) {
                        console.log("The status of the call: " + setTextAsyncResult.status);
                        console.log("The asyncContext value = " + setTextAsyncResult.asyncContext);
                });
            });
        });
    });
});

setTextAsync(text, callback)

カスタム XML パーツ内の XML ノードのテキストを非同期的に設定します。

setTextAsync(text: string, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

text

string

必須です。 XML ノードのテキスト値。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。

戻り値

void

注釈

要件セット: CustomXmlParts

setXmlAsync(xml, options, callback)

ノード XML を設定します。

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

パラメーター

xml

string

ノードに設定する XML

options
Office.AsyncContextOptions

コールバックで使用するために、任意の型のコンテキスト データを変更せずに保持するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。

戻り値

void

注釈

要件セット: CustomXmlParts

function setXmlNodeInnerXml() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getNodesAsync('*', function (nodeResults) {
            for (let i = 0; i < nodeResults.value.length; i++) {
                const node = nodeResults.value[i];
                node.setXmlAsync("<childNode>" + i + "</childNode>");
            }
        });
    });
}

setXmlAsync(xml, callback)

ノード XML を設定します。

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

パラメーター

xml

string

ノードに設定する XML

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。

戻り値

void

注釈

要件セット: CustomXmlParts