Skip to main content

UpdateAttribute

Updates an attribute of the XML node at the specified XPath.

Syntax​

expression.UpdateAttribute(xPath, name, value);

expression - A variable that represents an ApiCustomXmlPart class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
xPathRequiredstringThe XPath of the node whose attribute should be updated.
nameRequiredstringThe name of the attribute to update.
valueRequiredstringThe new value for the attribute.

Returns​

boolean

Example​

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

// How do I modify an existing attribute in an XML element in a presentation?

// Display the updated XML with the new attribute value in a presentation.

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