Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to count all the
XML
<Child>
node having value
XML
type="Note"


Example

XML
<Child type="Note"></Child>
<Child type="Pen"></Child>
<Child type="Note"></Child>
<Child type="Ruler"></Child>
<Child type="Note"></Child>


How to count the node <child> having Value type="Note".

How to do this with XML functions
Posted
Updated 30-Mar-14 21:24pm
v4

Please refer to the link:

Select XML Nodes by Attribute Value [C#][^]

Then you can use Count() method.

Good luck,
OI
 
Share this answer
 
Hello!

I think this is what you are looking for.

C#
XmlDocument xml = new XmlDocument();
int count;
xml.LoadXml(str);  

XmlNodeList xnList = xml.SelectNodes("/{ParentNode}/Child[@type='Book']");
count = xnList.count;


you can also refer this http://www.csharp-examples.net/xml-nodes-by-attribute-value/[^]

Hitesh Varde
Sr. Software Engineer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900