Share via


XMLNode.SelectSingleNode(String, String, Boolean) 方法

定義

取得 XMLNode 物件,代表第一個符合 XMLNode 控制項中 XPath 參數的子節點。

public Microsoft.Office.Interop.Word.XMLNode SelectSingleNode (string XPath, string PrefixMapping = "", bool FastSearchSkippingTextNodes = true);
abstract member SelectSingleNode : string * string * bool -> Microsoft.Office.Interop.Word.XMLNode
Public Function SelectSingleNode (XPath As String, Optional PrefixMapping As String = "", Optional FastSearchSkippingTextNodes As Boolean = true) As XMLNode

參數

XPath
String

有效的 XPath 字串。

PrefixMapping
String

提供要在結構描述中執行搜尋的前置詞。 PrefixMapping如果您的XPath參數使用名稱來搜尋元素,請使用 參數。

FastSearchSkippingTextNodes
Boolean

true 表示在搜尋指定節點時,要略過所有文字節點。 false 則表示要在搜尋中包含文字節點。 預設值為 true

傳回

符合 XMLNode 控制項中 XPath 參數的第一個子節點。

範例

下列程式代碼範例會 SelectSingleNode 使用 方法來取得符合指定 XPath 參數的子節點。 然後,此範例會顯示找到的節點名稱。 本範例假設目前的檔包含 XMLNode 具有相符架構專案的具名 CustomerNode ,其中包含一或多個名為 LastName的子節點。

private void FindLastNameNode()
{
    string element = "/x:Customer/x:LastName";
    string prefix = "xmlns:x='" + 
        this.CustomerLastNameNode.NamespaceURI + "'";

    Word.XMLNode node = this.CustomerNode.SelectSingleNode(element,
        prefix, true);
    if (node != null)
    {
        MessageBox.Show(node.BaseName + " element was found.");
    }
    else
    {
        MessageBox.Show("The requested node was not found.");
    }
}
Private Sub FindLastNameNode()
    Dim element As String = "/x:Customer/x:LastName"
    Dim prefix As String = "xmlns:x='" & _
        Me.CustomerLastNameNode.NamespaceURI & "'"

    Dim node As Word.XMLNode = _
        Me.CustomerNode.SelectSingleNode(element, prefix, True)
    If node IsNot Nothing Then
        MsgBox(node.BaseName & " element was found.")
    Else
        MsgBox("The requested node was not found.")
    End If
End Sub

備註

FastSearchSkippingTextNodes將 參數設定為false會降低效能,因為 Microsoft Office Word 會搜尋檔中包含之文字的所有節點。

選擇性參數

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

適用於