跳到主要内容

GetAttribute

返回指定 XPath 的 XML 节点的属性。

语法

expression.GetAttribute(xPath, name);

expression - 表示 ApiCustomXmlPart 类的变量。

参数

名称必需/可选数据类型默认值描述
xPath必需string要从中获取属性的节点的 XPath。
name必需string要查找的属性名称。

返回值

string | null

示例

从文档中嵌入的 XML 数据的元素读取命名属性的值。

// How do I get the value of a specific attribute from an XML element stored in a document?

// Extract a metadata value from structured XML so it can be displayed or validated 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);