跳到主要内容

SetAttribute

Sets an attribute for the custom XML node. If the attribute already exists, it will not be modified.

Syntax

expression.SetAttribute(name, value);

expression - A variable that represents a ApiCustomXmlNode class.

Parameters

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

Returns

boolean

Example

This example shows how to set an attribute value on a custom XML node.

// How to set attributes on custom XML node elements.

// Set attributes on product node.

let worksheet = Api.GetActiveSheet();
let xmlManager = worksheet.GetCustomXmlParts();
let xml = xmlManager.Add("<product></product>");
let productNode = xml.GetNodes('/product')[0];
productNode.SetAttribute("id", "456");
productNode.SetAttribute("name", "Desktop Computer");
productNode.SetAttribute("price", "1299");
let updatedXml = xml.GetXml();
worksheet.GetRange("A1").SetValue("Updated XML:");
worksheet.GetRange("A2").SetValue(updatedXml);