XMLNode.SelectNodes Method

Gets a Microsoft.Office.Interop.Word.XMLNodes collection that represents all the nodes that match the XPath parameter in the order in which they appear 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 SelectNodes ( _
    XPath As String, _
    PrefixMapping As String, _
    FastSearchSkippingTextNodes As Boolean _
) As XMLNodes
XMLNodes SelectNodes(
    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 false.

Return Value

Type: Microsoft.Office.Interop.Word.XMLNodes
The nodes that match the XPath parameter in the order in which they appear 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 SelectNodes method to get a collection of the child nodes that match the given XPath parameter. The example then displays the number of nodes that were 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 FirstName.

Private Sub DisplayFirstNameNodesCount()
    Dim element As String = "/x:Customer/x:FirstName"
    Dim prefix As String = "xmlns:x='" & _
        Me.CustomerFirstNameNode.NamespaceURI & "'"

    Dim nodes As Word.XMLNodes = _
        Me.CustomerNode.SelectNodes(element, prefix, True)
    MsgBox(nodes.Count & " element(s) were found.")
End Sub
private void DisplayFirstNameNodesCount()
{
    string element = "/x:Customer/x:FirstName";
    string prefix = "xmlns:x='" + 
        this.CustomerFirstNameNode.NamespaceURI + "'";

    Word.XMLNodes nodes = this.CustomerNode.SelectNodes(element, 
        prefix, true);
    MessageBox.Show(nodes.Count + " element(s) were found.");
}

.NET Framework Security

See Also

Reference

XMLNode Interface

Microsoft.Office.Tools.Word Namespace