跳到主要内容

UpdateAttribute

更新指定 XPath 的 XML 节点的属性。

语法

expression.UpdateAttribute(xPath, name, value);

expression - 表示 ApiCustomXmlPart 类的变量。

参数

名称必需/可选数据类型默认值描述
xPath必需string要更新其属性的节点的 XPath。
name必需string要更新的属性名称。
value必需string属性的新值。

返回值

boolean

示例

此示例演示如何更新自定义 XML 节点中属性的值。

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

const xmlManager = presentation.GetCustomXmlParts();
const xml = xmlManager.Add('<content xmlns="http://example" version="1.0"></content>');
xml.UpdateAttribute('/content', 'version', '2.0');

const fill = Api.CreateSolidFill(Api.HexColor('#00897B'));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('rect', 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());