How to count the number of XML nodes that contain a specific value

I am looking for how to count the nodes in an XML file that contain No, as well as the total number of elements.

My element counter is working fine, but I'm not sure of the logic to look in the XML to calculate the value.

To get the total score that I use:

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

Below is my 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> 

+4
source share
2 answers
 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; 

Good link here: http://msdn.microsoft.com/en-us/library/ms256086.aspx

+7
source

I am looking for how to count nodes in an XML file that contain a value of "No"

In XPath:

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

as well as the total number of items.

What you already have:

 count(/root/User) 

Or use an expression to select nodes and any DOM method to count Node Set Results.

+1
source

Source: https://habr.com/ru/post/1334982/


All Articles