XMLNode.SelectSingleNode(String, String, Boolean) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Parameters
- XPath
- String
A valid XPath string.
- PrefixMapping
- String
Provides the prefix in the schema against which to perform the search. Use the PrefixMapping
parameter if your XPath
parameter uses names to search for elements.
- FastSearchSkippingTextNodes
- Boolean
true
to skip all text nodes while searching for the specified node. false
to include text nodes in the search. Default value is true
.
Returns
The first child node that matches the XPath
parameter in the XMLNode control.
Examples
The following code example uses the SelectSingleNode method to get a child node that matches the given XPath
parameter. The example then displays the name of the node that was found. This example assumes that the current document contains an XMLNode named CustomerNode
with a matching schema element that contains one or more child nodes named 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
Remarks
Setting the FastSearchSkippingTextNodes
parameter to false
diminishes performance because Microsoft Office Word searches all nodes in a document for the text contained in the node.
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.