Share via


DocumentBase.SelectNodes 方法

取得 Microsoft.Office.Interop.Word.XMLNodes 集合,表示符合 XPath 參數的所有節點,這些節點會以在文件中出現的順序排列。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

'宣告
Public Function SelectNodes ( _
    xPath As String, _
    prefixMapping As String, _
    fastSearchSkippingTextNodes As Boolean _
) As XMLNodes
public XMLNodes SelectNodes(
    string xPath,
    string prefixMapping,
    bool fastSearchSkippingTextNodes
)

參數

  • xPath
    型別:System.String
    有效的 XPath 字串。如需關於 XPath 的詳細資訊,請參閱 XPath 參考。
  • prefixMapping
    型別:System.String
    提供要在結構描述中執行搜尋的前置詞。如果 XPath 參數是以名稱來搜尋項目,請使用 PrefixMapping 參數。
  • fastSearchSkippingTextNodes
    型別:System.Boolean
    true 表示在搜尋指定節點時,要略過所有文字節點。false 則表示要在搜尋中包含文字節點。預設值為 False。

傳回值

型別:Microsoft.Office.Interop.Word.XMLNodes
Microsoft.Office.Interop.Word.XMLNodes 集合,代表在文件中的顯示順序符合 XPath 參數的所有節點。如果找不到符合 XPath 參數的節點,則為 nullnull 參考 (即 Visual Basic 中的 Nothing)。

備註

將 FastSearchSkippingTextNodes 參數設定為 true 會減低效能,因為 Microsoft Office Word 會在文件的所有節點中搜尋包含在節點內的文字。

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例示範當呼叫 SelectNodes 方法時,如何指定 XPath 和 PrefixMapping 參數。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

Private Sub DocumentSelectNodes()
    If Me.XMLSchemaReferences.Count > 0 Then
        Dim XPath As String = "/x:catalog/x:book/x:title"
        Dim PrefixMapping As String = "xmlns:x=""" + _
            Me.XMLSchemaReferences(1).NamespaceURI + """"
        Dim node As Word.XMLNodes = Me.SelectNodes(XPath, _
            PrefixMapping, True)
    Else
        MessageBox.Show("The document does not contain a " + _
            "schema reference.")
    End If
End Sub
private void DocumentSelectNodes()
{
    if (this.XMLSchemaReferences.Count > 0)
    {
        string XPath = "/x:catalog/x:book/x:title";
        object key = 1;
        string PrefixMapping = "xmlns:x=\"" +
            this.XMLSchemaReferences[key].NamespaceURI +
            "\"";
        Word.XMLNodes nodes = this.SelectNodes(XPath, 
            PrefixMapping, true);
    }
    else
    {
        MessageBox.Show("The document does not contain a " +
            "schema reference.");
    }
}

.NET Framework 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間