Share via


Matching Nodes using XPathNavigator 

The XPathNavigator class provides the Matches method to determine if a node matches an XPath expression. The Matches method takes an XSL Transformations (XSLT) pattern as input and returns a Boolean that indicates if the current node matches the given XPath expression or the given compiled XPathExpression object.

Matching Nodes

The Matches method returns true if the current node matches the XPath expression specified. For example, in the code example that follows, the Matches method will return true if the current node is the element b, and element b has an attribute c.

Note

The Matches method does not change the state of the XPathNavigator.

Dim document as XPathDocument = New XPathDocument("input.xml")
Dim navigator as XPathNavigator = document.CreateNavigator()

navigator.Matches("b[@c]")
XPathDocument document = new XPathDocument("input.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.Matches("b[@c]");

See Also

Reference

XmlDocument
XPathDocument
XPathNavigator

Concepts

Process XML Data Using the XPath Data Model
Select XML Data using XPathNavigator
Evaluate XPath Expressions using XPathNavigator
Node Types Recognized with XPath Queries
XPath Queries and Namespaces
Compiled XPath Expressions