DocumentBase.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.
Returns a XMLNode object that represents the first node in the document that matches the XPath
parameter.
public Microsoft.Office.Interop.Word.XMLNode SelectSingleNode (string xPath, string prefixMapping, bool fastSearchSkippingTextNodes);
member this.SelectSingleNode : string * string * bool -> Microsoft.Office.Interop.Word.XMLNode
Public Function SelectSingleNode (xPath As String, Optional prefixMapping As String, Optional fastSearchSkippingTextNodes As Boolean) As XMLNode
Parameters
- xPath
- String
A valid XPath string. For more information about XPath, see XPath Reference.
- 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
skips all text nodes while searching for the specified node. false
includes text nodes in the search. Default value is false.
Returns
A XMLNode object that represents the first node that matches the XPath
parameter in the document; null
if no nodes matching the XPath
parameter are found.
Examples
The following code example demonstrates how to specify the XPath
and PrefixMapping
parameters when calling the SelectSingleNode method. To use this example, run it from the ThisDocument
class in a document-level project.
private void DocumentSelectSingleNode()
{
if (this.XMLSchemaReferences.Count > 0)
{
string XPath = "/x:catalog/x:book/x:title";
object key = 1;
string PrefixMapping = "xmlns:x=\"" +
this.XMLSchemaReferences.get_Item(ref key).NamespaceURI +
"\"";
Word.XMLNode node = this.SelectSingleNode(XPath,
PrefixMapping, true);
}
else
{
MessageBox.Show("The document does not contain a " +
"schema reference.");
}
}
Private Sub DocumentSelectSingleNode()
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.XMLNode = Me.SelectSingleNode(XPath, _
PrefixMapping, True)
Else
MessageBox.Show("The document does not contain a " + _
"schema reference.")
End If
End Sub
Remarks
Setting the FastSearchSkippingTextNodes
parameter to true
diminishes performance because Microsoft Office Word searches all nodes in a document against the text contained in the node.
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.