使用 XPathNavigator 匹配节点

XPathNavigator 类提供 Matches 用于确定节点是否与 XPath 表达式匹配的方法。 该方法 Matches 采用 XPath 表达式作为输入,并返回一个 Boolean 指示当前节点是否与给定的 XPath 表达式或给定编译 XPathExpression 的对象匹配。

匹配节点

如果当前节点与指定的 XPath 表达式匹配,则 Matches 该方法返回 true 。 例如,在下面的代码示例中,如果当前节点是元素Matches,并且元素true具有属性b,该方法b将返回c

注释

Matches 方法不会更改 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]");  

另请参阅