Skip to main content

GetAttribute

Returns an attribute from the XML node at the specified XPath.

Syntax

expression.GetAttribute(xPath, name);

expression - A variable that represents a ApiCustomXmlPart class.

Parameters

NameRequired/OptionalData typeDefaultDescription
xPathRequiredstringThe XPath of the node from which to get the attribute.
nameRequiredstringThe name of the attribute to find.

Returns

string | null

Example

Retrieve the value of the version attribute from the custom XML part in a document.

// How do I get the attribute in a document?

// Get the attribute using a custom XML part object in a document.

let doc = Api.GetDocument();
let xmlManager = doc.GetCustomXmlParts();
let xml = xmlManager.Add("<content xmlns='http://example' version='1.0'></content>");
let version = xml.GetAttribute("/content", "version");
let infoParagraph = Api.CreateParagraph();
infoParagraph.AddText("The version attribute is: " + version);
doc.Push(infoParagraph);