Skip to main content

InsertAttribute

Inserts an attribute into the XML node at the specified XPath.

Syntax

expression.InsertAttribute(xPath, name, value);

expression - A variable that represents a ApiCustomXmlPart class.

Parameters

NameRequired/OptionalData typeDefaultDescription
xPathRequiredstringThe XPath of the node to insert the attribute into.
nameRequiredstringThe name of the attribute to insert.
valueRequiredstringThe value of the attribute to insert.

Returns

boolean

Example

Insert an attribute into a custom XML node in a document.

// How to insert the attribute for a custom XML part in a document?

// Insert the attribute and display the result in a document.

let doc = Api.GetDocument();
let xmlManager = doc.GetCustomXmlParts();
let xml = xmlManager.Add("<content xmlns='http://example'></content>");
let insertionSuccess = xml.InsertAttribute("/content", "version", "1.0");
let paragraph = Api.CreateParagraph();
paragraph.AddText("XML string representation: " + xml.GetXml());
doc.Push(paragraph);