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
Name | Required/Optional | Data type | Default | Description |
---|---|---|---|---|
name | Required | string | The name of the attribute to set. | |
value | Required | string | The value to assign to the attribute. |
Returns
boolean
Example
This example shows how to get the XPath of a custom XML node.
- Code
- Result
let doc = Api.GetDocument();
let xmlManager = doc.GetCustomXmlParts();
let xmlText = `
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book>
<title lang="en">The Odyssey</title>
<author>Homer</author>
<year>-740</year>
<price>30.00</price>
</book>
</bookstore>`;
let xml = xmlManager.Add(xmlText);
let node = xml.GetNodes('/bookstore/book')[0];
node.SetAttribute('category', 'ancient');
let attributes = node.GetAttributes();
let paragraph = Api.CreateParagraph();
paragraph.AddText("Attributes of book node:\r\n");
attributes.forEach((attribute, index) => {
paragraph.AddText(`Attribute #${index} "${attribute.name}" with value: ${attribute.value}\r\n`);
});
doc.AddElement(0, paragraph);