Document.SelectSingleNode 方法 (Word)

會傳回代表符合 XPath 參數中指定的文件的第一個節點的 XMLNode 物件。

語法

expressionSelectSingleNode( _XPath_ , _PrefixMapping_ , _FastSearchSkippingTextNodes_ )

需要 expression。 代表 Document 物件的變數。

參數

名稱 必要/選用 資料類型 描述
XPath 必要 String 有效的 XPath 字串。 如需 XPath 的詳細資訊,請參閱 Microsoft Developer Network (MSDN) 網站上的 XPath 參考文件。
PrefixMapping 選用 Variant 提供結構描述中執行搜尋所根據的前置詞。 如果您的 XPath 參數使用名稱來搜尋項目,請使用 PrefixMapping 參數。
FastSearchSkippingTextNodes 選用 Boolean True 會略過所有項目的文字節點時搜尋指定的節點。 False 包含在搜尋中項目的文字節點。 預設值為 True

傳回值

XMLNode

註解

如果您將 FastSearchSkippingTextNodes 參數設定為 False 就會效能降低因為 Microsoft Word 會根據節點中包含的文字文件中搜尋所有節點。

範例

下列範例會傳回使用中文件內找到的第一個標題項目 (書籍項目的子項目)。

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 支援與意見反應