Csharp/C#教程:如何计算包含特定值的XML节点的数量分享


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

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

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

要获得我使用的总计数:

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

下面是我的XML:

    https://www.example.com Yes   https://www.example.com Yes   https://www.example.com Yes   https://www.example.com Yes   https://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方法来计算节点集结果成员。

上述就是C#学习教程:如何计算包含特定值的XML节点的数量分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/955255.html

(0)
上一篇 2021年11月21日
下一篇 2021年11月21日

精彩推荐