469,636 Members | 1,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

Count Nodes?

2
Hi there,

How do I count the number of <Item> nodes for each <Message> in the
following xml document?

(Xml Document)
<Message>
<Order>
<Item>1</Item>
<Item>2</Item>
</Order>
</Message>
<Message>
<Order>
<Item>3</Item>
</Order>
</Message>

I have succeded to count the number of <Message> nodes by doing following:

XmlDocument xmlD = new XmlDocument();
xmlD.Load(Server.MapPath("sample.xml"));
XmlNodeList xmlNL = xmlD.GetElementsByTagName("Message");
xmlNL.Count;

How do I count the number of <Item> tags for each <Message>?

Any help is appreciated.

Thanks,

JS
Dec 4 '06 #1
1 2220
JS1
2
I figured it out:

XmlDocument xmlD = new XmlDocument();
xmlD.Load(Server.MapPath("sample.xml"));

XmlNodeList xmlNL = xmlD.GetElementsByTagName("Message")[i].SelectNodes("Order/Item");

xmlNL.Count;

Thanks anyways,

JS
Dec 4 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by rob.guitar.rob | last post: by
6 posts views Thread by Tejpal Garhwal | last post: by
2 posts views Thread by Norton Who | last post: by
10 posts views Thread by John Rogers | last post: by
1 post views Thread by Derek Hart | last post: by
9 posts views Thread by smarttechie | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.