473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Count Nodes?

JS
Hi there,

How do I count the number of <Itemnodes for each <Messagein 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 <Messagenodes 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 <Itemtags for each <Message>?

Any help is appreciated.

Thanks,

JS

Dec 4 '06 #1
2 8206
JS
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
JS
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 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Fish | last post by:
Hi, I'm trying to use <xsl:number> to generate a sequence number of all nodes that match a particular pattern, e.g: <xsl:template match="foo"> <xsl:copy> <xsl:attribute name="id"><xsl:number...
3
by: rob.guitar.rob | last post by:
Hello, My last few posts have been revolving aroung the same problem, and I still cant solve it and I would be really appreciate if anyone could spot a problem. a section of my XML goes like...
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
2
by: Volkan | last post by:
Hi, I'm trying to compare two XML documents and i'm using XPath queries to select nodes. XPathNavigator's Select method runs fast enough and returns an XPathNodeIterator object. When i try to...
1
by: JS1 | last post by:
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>
2
by: Norton Who | last post by:
Hi, Could I please ask if anyone could help me solve this problem in VS2003: I'm trying to count all the nodes that have a Checked state however this doesn't seem to be working for me. So...
1
by: emorrison | last post by:
I hope this isn't too vague, but I have a large XML file and when I try to use a count function in an XSL file to get the number of nodes, it returns 0 for a particular node. I can correctly count...
10
by: John Rogers | last post by:
This code only counts the parent nodes or rootnodes in a treeview, how do you count all the nodes in a treeview? // one way int NodeCounter = 0; foreach (TreeNode currentNode in...
1
by: Derek Hart | last post by:
I wish to get a count of nodes in an xml file in vb.net, so I am using the following, as a simple example: MyCount = xmlNodePart.Current.Select.//MyNode/Record).Count I saw in some xml...
9
by: smarttechie | last post by:
Hii all please help its urgent i have developed an application in xsl. what i want to do is i m searching the xml file based on a search.and based on that search im creating one tree like...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.