UpdateElement
更新指定 XPath 的 XML 元素。
语法
expression.UpdateElement(xPath, xmlStr);
expression - 表示 ApiCustomXmlPart 类的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 默认值 | 描述 |
|---|---|---|---|---|
| xPath | 必需 | string | 要更新的节点的 XPath。 | |
| xmlStr | 必需 | string | 用于替换节点内容的 XML 字符串。 |
返回值
boolean
示例
此示例演示如何更新自定义 XML 部件中的 XML 元素。
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());