Skip to main content

UpdateAttribute

Updates the value of an existing attribute in the custom XML node. If the attribute doesn't exist, the update will not occur.

Syntax

expression.UpdateAttribute(name, value);

expression - A variable that represents a ApiCustomXmlNode class.

Parameters

NameRequired/OptionalData typeDefaultDescription
nameRequiredstringThe name of the attribute to update.
valueRequiredstringThe new value to assign to the attribute.

Returns

boolean

Example

Update the value of an existing attribute in a custom XML node in a presentation.

// How do I update attribute in a presentation?

// Update attribute using a custom XML node object in a presentation.

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());