473,408 Members | 2,734 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,408 software developers and data experts.

Counting nodes

Hi guys,

I know that counting of nodes is not a big deal. But I
need to do something where I cant get any solution. Here
is how my xml looks like.

<?xml version="1.0" encoding="utf-8"?>
<CategoryList>
<Category>
<MainCategory ID="3">XML</MainCategory>
<SubCategory>Basic</SubCategory>
<SubCategory>Advanced</SubCategory>
<SubCategory>blabla</SubCategory>
<Description>List of XML articles.</Description>
<Active>Yes</Active>
</Category>
<Category>
<MainCategory ID="2">C#</MainCategory>
<Description>List of C# articles.</Description>
<Active>Yes</Active>
</Category>
<Category>
<MainCategory ID="1">VC++</MainCategory>
<Description>A list of VC</Description>
<Active>Yes</Active>
</Category>
</CategoryList>

Now I am trying to count the SubCategories element of the
first Category element. This is how my code looks like.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("../dbase/categories.xml"));

string xmlQuery="/CategoryList/Category/MainCategory
[@ID='"+ddlMainCategory.SelectedValue.ToString()+"']";
XmlNodeList nodeList = xmlDoc.SelectNodes(xmlQuery);
for(int i=0;i<nodeList.Count;i++)
{
Response.Write(nodeList[i].Name);
if( nodeList[i].Name == "SubCategory")
Response.Write(nodeList.Item(i).ToString());
}

However my code only counts the MainCategory element,
which is fine according to the query. So can somebody tell
me how to count the SubCategories when I also have to
check the MainCategory ?

Thanks
Nov 12 '05 #1
1 1598
Problem is solved. Thanks anyway to all.

Sonu
-----Original Message-----
Hi guys,

I know that counting of nodes is not a big deal. But I
need to do something where I cant get any solution. Here
is how my xml looks like.

<?xml version="1.0" encoding="utf-8"?>
<CategoryList>
<Category>
<MainCategory ID="3">XML</MainCategory>
<SubCategory>Basic</SubCategory>
<SubCategory>Advanced</SubCategory>
<SubCategory>blabla</SubCategory>
<Description>List of XML articles.</Description>
<Active>Yes</Active>
</Category>
<Category>
<MainCategory ID="2">C#</MainCategory>
<Description>List of C# articles.</Description>
<Active>Yes</Active>
</Category>
<Category>
<MainCategory ID="1">VC++</MainCategory>
<Description>A list of VC</Description>
<Active>Yes</Active>
</Category>
</CategoryList>

Now I am trying to count the SubCategories element of the
first Category element. This is how my code looks like.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("../dbase/categories.xml"));

string xmlQuery="/CategoryList/Category/MainCategory
[@ID='"+ddlMainCategory.SelectedValue.ToString()+"']";
XmlNodeList nodeList = xmlDoc.SelectNodes(xmlQuery);
for(int i=0;i<nodeList.Count;i++)
{
Response.Write(nodeList[i].Name);
if( nodeList[i].Name == "SubCategory")
Response.Write(nodeList.Item(i).ToString());
}

However my code only counts the MainCategory element,
which is fine according to the query. So can somebody tellme how to count the SubCategories when I also have to
check the MainCategory ?

Thanks
.

Nov 12 '05 #2

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

Similar topics

3
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr>...
4
by: Victor Engmark | last post by:
When looking for a method to fetch unique elements and counting the number of occurences of each of them, I found quite a lot of gross examples of complex XSL. But after realizing the subtle...
1
by: anonymous | last post by:
Given a sample like the one below, how can I count the number of elements <quick> with the value 'yes'. When processing the //quick nodes I can easily find out if they are 'empty' but I need to...
4
by: dd | last post by:
Given the bolow sample, I need to count the elements <quick> with a child 'yes'. The result for this sample should, of couse, be '1', but I cannot figure out how to write the expression in the...
15
by: parksch2 | last post by:
I've spent quite a bit of time (way more than I'd like) today looking for an answer to what I thought would be a simple question. I simply need to get the count of items within some nodes up to the...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
2
by: Adam | last post by:
In my MYISAM table I have an index (Index_A) on 2 fields (Field_A, Field_B). There are millions of rows in the table. The cardinality of Index_A is 53. I think a query to count the number of rows...
4
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { }...
4
by: saritha2008 | last post by:
Hi, Iam working on converting one of xml file to other form of xml using XSLT. As part of this, I need to count the no. of "component" nodes in the xml file given below. If there is only one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.