跳到主要内容

UpdateAttribute

更新自定义 XML 节点中现有属性的值。 如果属性不存在,则不会执行更新。

语法

expression.UpdateAttribute(name, value);

expression - 表示 ApiCustomXmlNode 类的变量。

参数

名称必需/可选数据类型默认值描述
name必需string要更新的属性名称。
value必需string要分配给属性的新值。

返回值

boolean

示例

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

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

const xmlManager = presentation.GetCustomXmlParts();
const xmlText = '<bookstore><book category="house"><title lang="en">The Odyssey</title></book></bookstore>';
const xml = xmlManager.Add(xmlText);
const node = xml.GetNodes('/bookstore/book')[0];
node.UpdateAttribute('category', 'ancient');

const fill = Api.CreateSolidFill(Api.HexColor('#BB0066'));
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());