如何计算包含特定值的XML节点的数量

我正在寻找如何计算包含值“否”的XML文件中的节点以及元素的总数。

我的元素计数工作正常,但我不确定在XML中查找值的逻辑。

要获得我使用的总计数:

XmlDocument readDoc = new XmlDocument(); readDoc.Load(MapPath("Results.xml")); int count = readDoc.SelectNodes("root/User").Count; lblResults.Text = count.ToString(); 

下面是我的XML:

    http://www.example.com Yes   http://www.example.com Yes   http://www.example.com Yes   http://www.example.com Yes   http://www.example.com No  

 XmlDocument readDoc = new XmlDocument(); readDoc.Load(MapPath("Results.xml")); int count = readDoc.SelectNodes("root/User").Count; lblResults.Text = count.ToString(); int NoCount = readDoc.SelectNodes("JSEnabled[. = \"No\"]").Count; 

这里很好的参考: http : //msdn.microsoft.com/en-us/library/ms256086.aspx

我正在寻找如何计算包含值“否”的XML文件中的节点

在XPath中:

 count(/root/User[JSEnabled = 'No']) 

以及元素总数。

你已经拥有它:

 count(/root/User) 

或者使用表达式选择节点和任何DOM方法来计算节点集结果成员。