Поделиться через


DocumentBase.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 document.

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

Syntax

'Declaration
Public Function SelectNodes ( _
    xPath As String, _
    prefixMapping As String, _
    fastSearchSkippingTextNodes As Boolean _
) As XMLNodes
public XMLNodes SelectNodes(
    string xPath,
    string prefixMapping,
    bool fastSearchSkippingTextNodes
)

Parameters

  • xPath
    Type: System.String
    A valid XPath string. For more information on XPath, see XPath Reference.
  • 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 skips all text nodes while searching for the specified node. false includes text nodes in the search. Default value is false.

Return Value

Type: Microsoft.Office.Interop.Word.XMLNodes
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 document; nulla null reference (Nothing in Visual Basic) if no nodes matching the XPath parameter are found.

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.

Examples

The following code example demonstrates how to specify the XPath and PrefixMapping parameters when calling the SelectNodes method. To use this example, run it from the ThisDocument class in a document-level project.

Private Sub DocumentSelectNodes()
    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.XMLNodes = Me.SelectNodes(XPath, _
            PrefixMapping, True)
    Else
        MessageBox.Show("The document does not contain a " + _
            "schema reference.")
    End If
End Sub
private void DocumentSelectNodes()
{
    if (this.XMLSchemaReferences.Count > 0)
    {
        string XPath = "/x:catalog/x:book/x:title";
        object key = 1;
        string PrefixMapping = "xmlns:x=\"" +
            this.XMLSchemaReferences[key].NamespaceURI +
            "\"";
        Word.XMLNodes nodes = this.SelectNodes(XPath, 
            PrefixMapping, true);
    }
    else
    {
        MessageBox.Show("The document does not contain a " +
            "schema reference.");
    }
}

.NET Framework Security

See Also

Reference

DocumentBase Class

Microsoft.Office.Tools.Word Namespace