跳到主要内容

UpdateElement

Updates an XML element at the specified XPath.

Syntax

expression.UpdateElement(xPath, xmlStr);

expression - A variable that represents a ApiCustomXmlPart class.

Parameters

NameRequired/OptionalData typeDefaultDescription
xPathRequiredstringThe XPath of the node to update.
xmlStrRequiredstringThe XML string to replace the node content with.

Returns

boolean

Example

This example shows how to update an XML element in a custom XML part.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const xmlManager = presentation.GetCustomXmlParts();
const xml = xmlManager.Add('<content xmlns="http://example"><text>Example</text></content>');
xml.UpdateElement('/content', '<user>John</user>');

const fill = Api.CreateSolidFill(Api.RGB(66, 133, 191));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('roundRect', Api.MillimetersToEmus(300), Api.MillimetersToEmus(130), fill, stroke);
shape.SetPosition(Api.MillimetersToEmus(20), Api.MillimetersToEmus(35));
slide.AddObject(shape);

const docContent = shape.GetContent();
const paragraph = docContent.GetElement(0);
paragraph.AddText('XML after update: ' + xml.GetXml());