XMLNode.SelectSingleNode(String, String, Boolean) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
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 方案中的選擇性參數。