Document.SelectSingleNode 方法 (Word)

返回一个 XMLNode 对象,代表指定文档中的 XPath 参数相匹配的第一个节点。

语法

expression. SelectSingleNode( _XPath_ , _PrefixMapping_ , _FastSearchSkippingTextNodes_ )

expression 是必需的。 一个代表 Document 对象的变量。

参数

名称 必需/可选 数据类型 说明
XPath 必需 String 有效的 XPath 字符串。 有关 XPath 的详细信息,请参阅 Microsoft Developer Network (MSDN) 网站上的 XPath 参考文档。
PrefixMapping 可选 Variant 提供用于搜索的架构中的前缀。 如果 XPath 参数使用名称来搜索元素,则可使用 PrefixMapping 参数。
FastSearchSkippingTextNodes 可选 Boolean 为 所有文本节点都搜索时跳过指定的节点。 假 在搜索中包含文本节点。 默认值为 True 。

返回值

XMLNode

备注

将 FastSearchSkippingTextNodes 参数设置为 False 会降低性能,因为 Microsoft Word 搜索包含在节点中的文本与文档中的所有节点。

示例

以下示例返回在活动文档中找到的第一个 title 元素,该元素是 book 元素的子元素。

Dim objElement As XMLNode 
Dim strElement As String 
Dim strPrefix As String 
 
strElement = "/x:catalog/x:book/x:title" 
strPrefix = "xmlns:x=""" & ActiveDocument _ 
 .XMLSchemaReferences(1).NamespaceURI & """" 
 
Set objElement = ActiveDocument _ 
 .SelectSingleNode(strElement, strPrefix)

另请参阅

Document 对象

支持和反馈

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