Export (0) Print
Expand All
Expand Minimize

Document.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 (in microsoft.office.tools.word.dll)

public virtual XMLNodes SelectNodes (
	string XPath,
	[OptionalAttribute] string PrefixMapping,
	[OptionalAttribute] bool FastSearchSkippingTextNodes
)

Parameters

XPath

A valid XPath string. For more information on XPath, see the XPath reference documentation on the Microsoft Developer Network (MSDN) Web site.

PrefixMapping

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

true skips all text nodes while searching for the specified node. false includes text nodes in the search. Default value is false.

Return Value

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.

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 Understanding Optional Parameters in COM Interop.

The following code example demonstrates how to specify the XPath and PrefixMapping parameters when calling the SelectNodes method.

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.get_Item(ref key).NamespaceURI +
            "\"";

        Word.XMLNodes nodes = this.SelectNodes(XPath, 
            PrefixMapping, true);
    }
    else
    {
        MessageBox.Show("The document does not contain a " +
            "schema reference.");
    }
}

Show:
© 2014 Microsoft