Share via


XMLNode.SelectSingleNode Method

Gets a Microsoft.Office.Interop.Word.XMLNode object that represents the first child node that matches the XPath parameter in the Microsoft.Office.Tools.Word.XMLNode control.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Function SelectSingleNode ( _
    XPath As String, _
    PrefixMapping As String, _
    FastSearchSkippingTextNodes As Boolean _
) As XMLNode
XMLNode SelectSingleNode(
    string XPath,
    string PrefixMapping,
    bool FastSearchSkippingTextNodes
)

Parameters

  • PrefixMapping
    Type: System.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
    Type: System.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.

Return Value

Type: Microsoft.Office.Interop.Word.XMLNode
The first child node that matches the XPath parameter in the Microsoft.Office.Tools.Word.XMLNode control.

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.

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 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
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.");
    }
}

.NET Framework Security

See Also

Reference

XMLNode Interface

Microsoft.Office.Tools.Word Namespace