跳到主要内容

GetNodes

根据提供的 XPath 从自定义 XML 检索节点。

语法

expression.GetNodes(xPath);

expression - 表示 ApiCustomXmlPart 类的变量。

参数

名称必需/可选数据类型默认值描述
xPath必需string用于搜索节点的 XPath 表达式。

返回值

ApiCustomXmlNode[]

示例

此示例演示如何更新自定义 XML 节点中属性的值。

let doc = Api.GetDocument();
let xmlManager = doc.GetCustomXmlParts();
let xmlText = `
<?xml version="1.0" encoding="UTF-8"?>
<documentData xmlns="http://example.com/example">
<text val="123">node text</text>
<label name="Title">label text</label>
</documentData>`;
let xml = xmlManager.Add(xmlText);
let nodes = xml.GetNodes("/documentData/*");
let label = xml.GetNodes("/documentData/label")[0];
let paragraph = Api.CreateParagraph();
nodes.forEach(node => {
paragraph.AddText("Node text: " + node.GetText() + "\r\n");
});
paragraph.AddText("Label attribute: " + label.GetAttribute("name"));
doc.Push(paragraph);