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

C# 如何计算包含特定值的XML节点数,c#,xml,xpath,C#,Xml,Xpath,我正在寻找如何计算XML文件中包含“No”值以及元素总数的节点数 我的元素计数工作正常,但我不确定在XML中查找要计数的值的逻辑 要获取我使用的总计数,请执行以下操作: XmlDocument readDoc = new XmlDocument(); readDoc.Load(MapPath("Results.xml")); int count = readDoc.SelectNodes("root/User").Count; lblResults.Text =

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

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

要获取我使用的总计数,请执行以下操作:

    XmlDocument readDoc = new XmlDocument();
    readDoc.Load(MapPath("Results.xml"));
    int count = readDoc.SelectNodes("root/User").Count;
    lblResults.Text = count.ToString();
下面是我的XML:

<?xml version="1.0" encoding="iso-8859-1"?>
<root>
  <User>
    <URL>http://www.example.com</URL>
    <JSEnabled>Yes</JSEnabled>
  </User>
  <User>
   <URL>http://www.example.com</URL>
   <JSEnabled>Yes</JSEnabled>
 </User>
 <User>
   <URL>http://www.example.com</URL>
   <JSEnabled>Yes</JSEnabled>
 </User>
 <User>
   <URL>http://www.example.com</URL>
   <JSEnabled>Yes</JSEnabled>
 </User>
 <User>
   <URL>http://www.example.com</URL>
   <JSEnabled>No</JSEnabled>
 </User>

http://www.example.com
对
http://www.example.com
对
http://www.example.com
对
http://www.example.com
对
http://www.example.com
不

这里有很好的参考:

我在找如何数数数字 XML文件中包含 “否”的价值

在XPath中:

count(/root/User[JSEnabled = 'No'])
以及 元素

您已经拥有它:

count(/root/User)

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

这满足了我的要求,但在阅读了该参考链接后,我能够获得比我最初寻找的更多的结果。非常感谢
NoCount
应该是
XmlNodeList
而不是
int
。或者,您应该使用
readDoc.SelectNodes(“JSEnabled[.=\“No\”])。Count
count(/root/User)