CompositeNodeSelectSingleNode Method
Selects the first Node that matches the XPath expression.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
public Node SelectSingleNode(
	string xpath


Type: SystemString
The XPath expression.

Return Value

Type: Node
The first Node that matches the XPath query or null if no matching node is found.

Only expressions with element names are supported at the moment. Expressions that use attribute names are not supported.

Shows how to select certain nodes by using an XPath expression.

Document doc = new Document(MyDir + "Table.Document.doc");

// This expression will extract all paragraph nodes which are descendants of any table node in the document.
// This will return any paragraphs which are in a table.
NodeList nodeList = doc.SelectNodes("//Table//Paragraph");

// This expression will select any paragraphs that are direct children of any body node in the document.
nodeList = doc.SelectNodes("//Body/Paragraph");

// Use SelectSingleNode to select the first result of the same expression as above.
Node node = doc.SelectSingleNode("//Body/Paragraph");
See Also