Share via


使用 XPathNavigator 匹配节点

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

匹配节点

如果当前节点与指定的 XPath 表达式匹配,Matches 方法将返回 true。 例如,在以下代码示例中,如果当前节点为元素 Matches,并且元素 true 具有属性 bb 方法将返回 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]");  

请参阅