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 an attribute of the XML element found by its path in a spreadsheet.

// How do I overwrite the current value of a named property on an XML node in a spreadsheet?

// Revise stored XML metadata by updating a specific attribute to a new value in a spreadsheet.

const worksheet = Api.GetActiveSheet();
const xmlManager = worksheet.GetCustomXmlParts();
const xmlString = "<config version='1.0' namespace='http://api.onlyoffice.com' />";
const xml = xmlManager.Add(xmlString);

xml.UpdateAttribute('/config', 'version', '9.4');
worksheet.GetRange('A1').SetValue('XML after update: ' + xml.GetXml());