Office.CustomXmlNode interface

Stellt einen XML-Knoten in einer Struktur in einem Dokument dar.

Hinweise

Anwendungen: Word

Eigenschaften

baseName

Ruft den Basisnamen des Knotens ohne Namespacepräfix ab, falls vorhanden.

namespaceUri

Ruft die Zeichenfolgendarstellung der GUID des Objekts CustomXMLPart ab.

nodeType

Ruft den Typ des CustomXMLNode-Objekts ab.

Methoden

getNodesAsync(xPath, options, callback)

Ruft die Knoten ab, die dem XPath-Ausdruck zugeordnet sind.

getNodesAsync(xPath, callback)

Ruft die Knoten ab, die dem XPath-Ausdruck zugeordnet sind.

getNodeValueAsync(options, callback)

Ruft den Knotenwert ab.

getNodeValueAsync(callback)

Ruft den Knotenwert ab.

getTextAsync(options, callback)

Ruft den Text eines XML-Knotens in einer benutzerdefinierten XML-Komponente ab.

getTextAsync(callback)

Ruft den Text eines XML-Knotens in einer benutzerdefinierten XML-Komponente ab.

getXmlAsync(options, callback)

Ruft den XML-Code des Knotens ab.

getXmlAsync(callback)

Ruft den XML-Code des Knotens ab.

setNodeValueAsync(value, options, callback)

Legt den Knotenwert fest.

setNodeValueAsync(value, callback)

Legt den Knotenwert fest.

setTextAsync(text, options, callback)

Legt den Text eines XML-Knotens in einer benutzerdefinierten XML-Komponente asynchron fest.

setTextAsync(text, callback)

Legt den Text eines XML-Knotens in einer benutzerdefinierten XML-Komponente asynchron fest.

setXmlAsync(xml, options, callback)

Legt die Knoten-XML fest.

setXmlAsync(xml, callback)

Legt die Knoten-XML fest.

Details zur Eigenschaft

baseName

Ruft den Basisnamen des Knotens ohne Namespacepräfix ab, falls vorhanden.

baseName: string;

Eigenschaftswert

string

Beispiele

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

Ruft die Zeichenfolgendarstellung der GUID des Objekts CustomXMLPart ab.

namespaceUri: string;

Eigenschaftswert

string

Beispiele

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

Ruft den Typ des CustomXMLNode-Objekts ab.

nodeType: string;

Eigenschaftswert

string

Beispiele

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; 
}

Details zur Methode

getNodesAsync(xPath, options, callback)

Ruft die Knoten ab, die dem XPath-Ausdruck zugeordnet sind.

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

Parameter

xPath

string

Der XPath-Ausdruck, der die abzurufenden Knoten angibt. Erforderlich.

options
Office.AsyncContextOptions

Bietet eine Option zum Beibehalten von Kontextdaten eines beliebigen Typs , unverändert, für die Verwendung in einem Rückruf.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist. Die value -Eigenschaft des Ergebnisses ist ein Array von CustomXmlNode-Objekten, die die Knoten darstellen, die durch den XPath-Ausdruck angegeben werden, der an den xPath Parameter übergeben wird.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

getNodesAsync(xPath, callback)

Ruft die Knoten ab, die dem XPath-Ausdruck zugeordnet sind.

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

Parameter

xPath

string

Der XPath-Ausdruck, der die abzurufenden Knoten angibt. Erforderlich.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist. Die value -Eigenschaft des Ergebnisses ist ein Array von CustomXmlNode-Objekten, die die Knoten darstellen, die durch den XPath-Ausdruck angegeben werden, der an den xPath Parameter übergeben wird.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

Beispiele

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)

Ruft den Knotenwert ab.

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

Parameter

options
Office.AsyncContextOptions

Bietet eine Option zum Beibehalten von Kontextdaten eines beliebigen Typs , unverändert, für die Verwendung in einem Rückruf.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist. Die value -Eigenschaft des Ergebnisses ist eine Zeichenfolge, die den Wert des Knotens enthält, auf den verwiesen wird.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

getNodeValueAsync(callback)

Ruft den Knotenwert ab.

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

Parameter

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist. Die value -Eigenschaft des Ergebnisses ist eine Zeichenfolge, die den Wert des Knotens enthält, auf den verwiesen wird.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

Beispiele

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)

Ruft den Text eines XML-Knotens in einer benutzerdefinierten XML-Komponente ab.

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

Parameter

options
Office.AsyncContextOptions

Bietet eine Option zum Beibehalten von Kontextdaten eines beliebigen Typs , unverändert, für die Verwendung in einem Rückruf.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist. Die value -Eigenschaft des Ergebnisses ist eine Zeichenfolge, die den inneren Text der Knoten enthält, auf die verwiesen wird.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

Beispiele

// 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)

Ruft den Text eines XML-Knotens in einer benutzerdefinierten XML-Komponente ab.

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

Parameter

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist. Die value -Eigenschaft des Ergebnisses ist eine Zeichenfolge, die den inneren Text der Knoten enthält, auf die verwiesen wird.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

getXmlAsync(options, callback)

Ruft den XML-Code des Knotens ab.

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

Parameter

options
Office.AsyncContextOptions

Bietet eine Option zum Beibehalten von Kontextdaten eines beliebigen Typs , unverändert, für die Verwendung in einem Rückruf.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist. Die value -Eigenschaft des Ergebnisses ist eine Zeichenfolge, die den XML-Code des Knotens enthält, auf den verwiesen wird.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

getXmlAsync(callback)

Ruft den XML-Code des Knotens ab.

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

Parameter

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist. Die value -Eigenschaft des Ergebnisses ist eine Zeichenfolge, die den XML-Code des Knotens enthält, auf den verwiesen wird.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

Beispiele

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)

Legt den Knotenwert fest.

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

Parameter

value

string

Der Wert, der auf dem Knoten festgelegt werden soll

options
Office.AsyncContextOptions

Bietet eine Option zum Beibehalten von Kontextdaten eines beliebigen Typs , unverändert, für die Verwendung in einem Rückruf.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

setNodeValueAsync(value, callback)

Legt den Knotenwert fest.

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

Parameter

value

string

Der Wert, der auf dem Knoten festgelegt werden soll

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

Beispiele

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)

Legt den Text eines XML-Knotens in einer benutzerdefinierten XML-Komponente asynchron fest.

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

Parameter

text

string

Erforderlich. Der Textwert des XML-Knotens.

options
Office.AsyncContextOptions

Bietet eine Option zum Beibehalten von Kontextdaten eines beliebigen Typs , unverändert, für die Verwendung in einem Rückruf.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

Beispiele

// 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)

Legt den Text eines XML-Knotens in einer benutzerdefinierten XML-Komponente asynchron fest.

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

Parameter

text

string

Erforderlich. Der Textwert des XML-Knotens.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

setXmlAsync(xml, options, callback)

Legt die Knoten-XML fest.

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

Parameter

xml

string

Der XML-Code, der auf dem Knoten festgelegt werden soll

options
Office.AsyncContextOptions

Bietet eine Option zum Beibehalten von Kontextdaten eines beliebigen Typs , unverändert, für die Verwendung in einem Rückruf.

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts

Beispiele

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)

Legt die Knoten-XML fest.

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

Parameter

xml

string

Der XML-Code, der auf dem Knoten festgelegt werden soll

callback

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

Optional. Eine Funktion, die aufgerufen wird, wenn der Rückruf zurückgibt, deren einziger Parameter vom Typ Office.AsyncResult ist.

Gibt zurück

void

Hinweise

Anforderungssatz: CustomXmlParts