跳到主要内容

GetNodes

根据给定的 XPath 从自定义 XML 节点返回节点。

语法

expression.GetNodes(xPath);

expression - 表示 ApiCustomXmlNode 类的变量。

参数

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

返回值

ApiCustomXmlNode[]

示例

使用路径查询从文档中的自定义 XML 节点选择子节点。

// How do I retrieve matching child nodes from a custom XML node in a document?

// Traverse embedded XML data by querying for a set of elements under a given node in a document.

let doc = Api.GetDocument();
let xmlManager = doc.GetCustomXmlParts();
let xmlText = `
<?xml version="1.0" encoding="UTF-8"?>
<zoo>
<animal species="Lion" id="101">
<name>Leo</name>
<age>5</age>
<habitat>Savanna</habitat>
<diet>Carnivore</diet>
</animal>
</zoo>`;
let xml = xmlManager.Add(xmlText);
let animalNode = xml.GetNodes('/zoo/animal')[0];
let nodes = animalNode.GetNodes("/*");
let paragraph = Api.CreateParagraph();
nodes.forEach(function(node, index) {
paragraph.AddText(`Node #${index} value: ${node.GetNodeValue()}\r\n`);
});
doc.Push(paragraph);