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 XPath expression 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