CustomXMLNode.SelectSingleNode 方法 (Office)

从与 XPath 表达式匹配的集合中选择一个节点。 此方法与 CustomXMLPart.SelectSingleNode 方法的不同之处在于,XPath 表达式将从“expression”节点作为上下文节点开始计算。

语法

表达式selectSingleNode (XPath)

表达 返回 CustomXMLNode 对象的表达式。

参数

名称 必需/可选 数据类型 说明
XPath 必需 String 包含一个 XPath 表达式。

返回值

CustomXMLNode

备注

XPath 表达式的前缀映射是从 NamespaceManager 属性检索的。

示例

以下示例说明了添加自定义 XML 部件,选择具有命名空间 URI 的部件,然后在该部件内选择与 XPath 表达式匹配的节点。

Dim cxp1 As CustomXMLPart 
Dim cxn As CustomXMLNode 
 
' Add a custom xml part. 
ActiveDocument.CustomXMLParts.Add "<supplier>" 
 
' Return the first custom xml part with the given namespace. 
Set cxp1 = ActiveDocument.CustomXMLParts("urn:invoice:namespace")         
 
' Get a node using XPath.                              
 Set cxn = cxp1(1).SelectSingleNode("//*[@supplierID = 1]") 

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。