如何在C#中使用XPath获取SelectedNode的计数? [英] How to get count number of SelectedNode with XPath in C#?
问题描述
我使用HTMLAgilityPack在我的应用程序,我想SelectedNodes如下面的代码的项目(节点)数:
I am using HTMLAgilityPack in my application, and i want to get the item(node) count of SelectedNodes as the code below:
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(webBrowser1.DocumentText);
var tagListe = doc.DocumentNode.SelectNodes("//a[@href]");
var divListe = doc.DocumentNode.SelectNodes("//div[@class='o']");
在第一,得到A HREF已成功运行,但第二个我宁愿得到特殊类命名O有恩的错误。
At the first, getting a href was successfully running, but second one i prefer to get special class named "o" there was en error.
我想用.Count之间,但得到了一个错误。此外foreach循环运行杉杉selectedNodes我请求标签href属性。并没有上课过滤运行。
I want to use .Count but got an error. Also foreach loop running for the firs selectedNodes which i request a tags href attribute. And didn't run for class filtering.
热卖获得 doc.DocumentNode.SelectNodes(// DIV [@类的数量=' O'])
感谢您,
卡格拉
Thank you, Caglar
推荐答案
我不知道在 HTMLAgilityPack
但在普通的XPath,你可以这样做:
I don't know the specific way in HTMLAgilityPack
but in plain XPath you can do this:
计数(// DIV [@类='O'])
您正确不能在 .SelectNodes
使用XPath的,但应该有像的方法评估
, SelectSingle
或 SelectAtom
。
You properly can't use this XPath in .SelectNodes
but there should be a method like Evaluate
, SelectSingle
or SelectAtom
.
这篇关于如何在C#中使用XPath获取SelectedNode的计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!