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

Childnodes property reports only one node...

Hi:

I'm trying to loop through an XML document but ChildNodes property reports
only one node, but there are many. XML document is valid. What am I doing
wrong?

foreach( XmlNode node in xml.ChildNodes ) { }

Below is XML...

<Catalog>
<Category>
<CategoryName>Drivers</CategoryName>
<Subcategory>
<SubcategoryName>Tweeters</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>.5 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>.5 Metal Dome Tweeter</ShortDescription>
<Price>25.9600</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>.75 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>.75 Fabric Dome Tweeter</ShortDescription>
<Price>28.9900</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>1 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>1 Fabric Dome Tweeter</ShortDescription>
<Price>55.0000</Price>
</Product>
<Product>
<ShortDescription>1 Meal Dome Tweeter</ShortDescription>
<Price>44.0000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Mid-Ranges</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>5.25 inch
Mid-Ranges</SubCategorySubCategoryName>
<Product>
<ShortDescription>5.25 Poly Mid-range</ShortDescription>
<Price>55.0000</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>3 inch Dome
Mid-Ranges</SubCategorySubCategoryName>
<Product>
<ShortDescription>3 Metal Dome Mid-range</ShortDescription>
<Price>89.5000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Woofers</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>6.5 inch Woofers</SubCategorySubCategoryName>
<Product>
<ShortDescription>6.5 Paper Cone Woofer</ShortDescription>
<Price>125.0000</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>10 inch Woofers</SubCategorySubCategoryName>
<Product>
<ShortDescription>10 Poly Cone Woofer</ShortDescription>
<Price>175.0000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
</Category>
<Category>
<CategoryName>Electrical Components</CategoryName>
<Subcategory>
<SubcategoryName>Resistors</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Metal Film
Resistors</SubCategorySubCategoryName>
<Product>
<ShortDescription>220 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
<Product>
<ShortDescription>300 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
<Product>
<ShortDescription>500 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Carbon Resistors</SubCategorySubCategoryName>
<Product>
<ShortDescription>300 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>220 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>500 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Capacitors</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Bi-Polar Capacitors</SubCategorySubCategoryName>
<Product>
<ShortDescription>10 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>12 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>15 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Non-Polarized
Capacitors</SubCategorySubCategoryName>
<Product>
<ShortDescription>.15 uF Poly</ShortDescription>
<Price>0.9900</Price>
</Product>
<Product>
<ShortDescription>.35 uF Poly</ShortDescription>
<Price>1.5000</Price>
</Product>
<Product>
<ShortDescription>.0015 uF Poly</ShortDescription>
<Price>2.9500</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
</Category>
</Catalog>

Thanks,
Charlie
Dec 13 '06 #1
2 1184
On Wed, 13 Dec 2006 13:02:32 -0500, "Charlie@CBFC"
<ch*****@cbfconsulting.comwrote:
>Hi:

I'm trying to loop through an XML document but ChildNodes property reports
only one node, but there are many. XML document is valid. What am I doing
wrong?

foreach( XmlNode node in xml.ChildNodes ) { }
I suspect the xml object is of type XmlDocument and the one child node
found is named Catalog. Examine the XmlDocument.DocumentNode property.

regards
A.G.
>Below is XML...

<Catalog>
<Category>
<CategoryName>Drivers</CategoryName>
<Subcategory>
<SubcategoryName>Tweeters</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>.5 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>.5 Metal Dome Tweeter</ShortDescription>
<Price>25.9600</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>.75 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>.75 Fabric Dome Tweeter</ShortDescription>
<Price>28.9900</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>1 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>1 Fabric Dome Tweeter</ShortDescription>
<Price>55.0000</Price>
</Product>
<Product>
<ShortDescription>1 Meal Dome Tweeter</ShortDescription>
<Price>44.0000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Mid-Ranges</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>5.25 inch
Mid-Ranges</SubCategorySubCategoryName>
<Product>
<ShortDescription>5.25 Poly Mid-range</ShortDescription>
<Price>55.0000</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>3 inch Dome
Mid-Ranges</SubCategorySubCategoryName>
<Product>
<ShortDescription>3 Metal Dome Mid-range</ShortDescription>
<Price>89.5000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Woofers</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>6.5 inch Woofers</SubCategorySubCategoryName>
<Product>
<ShortDescription>6.5 Paper Cone Woofer</ShortDescription>
<Price>125.0000</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>10 inch Woofers</SubCategorySubCategoryName>
<Product>
<ShortDescription>10 Poly Cone Woofer</ShortDescription>
<Price>175.0000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
</Category>
<Category>
<CategoryName>Electrical Components</CategoryName>
<Subcategory>
<SubcategoryName>Resistors</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Metal Film
Resistors</SubCategorySubCategoryName>
<Product>
<ShortDescription>220 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
<Product>
<ShortDescription>300 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
<Product>
<ShortDescription>500 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Carbon Resistors</SubCategorySubCategoryName>
<Product>
<ShortDescription>300 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>220 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>500 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Capacitors</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Bi-Polar Capacitors</SubCategorySubCategoryName>
<Product>
<ShortDescription>10 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>12 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>15 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Non-Polarized
Capacitors</SubCategorySubCategoryName>
<Product>
<ShortDescription>.15 uF Poly</ShortDescription>
<Price>0.9900</Price>
</Product>
<Product>
<ShortDescription>.35 uF Poly</ShortDescription>
<Price>1.5000</Price>
</Product>
<Product>
<ShortDescription>.0015 uF Poly</ShortDescription>
<Price>2.9500</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
</Category>
</Catalog>

Thanks,
Charlie
Dec 13 '06 #2
Keep in mind, you're not dealing with a collection of nodes, you're dealing
with a hierarchical collection of nodes. The document has one childnode,
Catalog, when viewed from the root. If you then set then set the parent node
to be that particular childnode, you'll find a number of childnodes equal to
the number of category elements in the document and so on. To really go
through the document object you'll have to use a recursive function that
basically receives a childnode property which then becomes the parent node
for that function. The funciton then iterates through all the childnodes and
performs some operation (like dumping the value to a trace) and then calls
itself, passing that particular childnode to the function to become a parent
node to find all it's children.

--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Charlie@CBFC" <ch*****@cbfconsulting.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi:

I'm trying to loop through an XML document but ChildNodes property reports
only one node, but there are many. XML document is valid. What am I
doing wrong?

foreach( XmlNode node in xml.ChildNodes ) { }

Below is XML...

<Catalog>
<Category>
<CategoryName>Drivers</CategoryName>
<Subcategory>
<SubcategoryName>Tweeters</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>.5 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>.5 Metal Dome Tweeter</ShortDescription>
<Price>25.9600</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>.75 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>.75 Fabric Dome Tweeter</ShortDescription>
<Price>28.9900</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>1 inch Dome
Tweeters</SubCategorySubCategoryName>
<Product>
<ShortDescription>1 Fabric Dome Tweeter</ShortDescription>
<Price>55.0000</Price>
</Product>
<Product>
<ShortDescription>1 Meal Dome Tweeter</ShortDescription>
<Price>44.0000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Mid-Ranges</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>5.25 inch
Mid-Ranges</SubCategorySubCategoryName>
<Product>
<ShortDescription>5.25 Poly Mid-range</ShortDescription>
<Price>55.0000</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>3 inch Dome
Mid-Ranges</SubCategorySubCategoryName>
<Product>
<ShortDescription>3 Metal Dome Mid-range</ShortDescription>
<Price>89.5000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Woofers</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>6.5 inch Woofers</SubCategorySubCategoryName>
<Product>
<ShortDescription>6.5 Paper Cone Woofer</ShortDescription>
<Price>125.0000</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>10 inch Woofers</SubCategorySubCategoryName>
<Product>
<ShortDescription>10 Poly Cone Woofer</ShortDescription>
<Price>175.0000</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
</Category>
<Category>
<CategoryName>Electrical Components</CategoryName>
<Subcategory>
<SubcategoryName>Resistors</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Metal Film
Resistors</SubCategorySubCategoryName>
<Product>
<ShortDescription>220 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
<Product>
<ShortDescription>300 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
<Product>
<ShortDescription>500 ohm Metal Film</ShortDescription>
<Price>0.2500</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Carbon Resistors</SubCategorySubCategoryName>
<Product>
<ShortDescription>300 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>220 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>500 ohm Carbon</ShortDescription>
<Price>0.1500</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
<Subcategory>
<SubcategoryName>Capacitors</SubcategoryName>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Bi-Polar
Capacitors</SubCategorySubCategoryName>
<Product>
<ShortDescription>10 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>12 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
<Product>
<ShortDescription>15 uF Bi-Polar</ShortDescription>
<Price>0.1500</Price>
</Product>
</SubCategorySubCategory>
<SubCategorySubCategory>
<SubCategorySubCategoryName>Non-Polarized
Capacitors</SubCategorySubCategoryName>
<Product>
<ShortDescription>.15 uF Poly</ShortDescription>
<Price>0.9900</Price>
</Product>
<Product>
<ShortDescription>.35 uF Poly</ShortDescription>
<Price>1.5000</Price>
</Product>
<Product>
<ShortDescription>.0015 uF Poly</ShortDescription>
<Price>2.9500</Price>
</Product>
</SubCategorySubCategory>
</Subcategory>
</Category>
</Catalog>

Thanks,
Charlie

Dec 14 '06 #3

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

Similar topics

4
by: Skip Montanaro | last post by:
I'm getting somewhat painfully acquainted with xml.dom.minidom. What is the relationship between its documentElement attribute and its childNodes list? I thought XML documents consisted of a...
7
by: adam | last post by:
i'm working on a portion of a CMS that allows content-admins to browse a product list, and add individual products into the taxonomy by clicking checkboxes next to categories they might belong in....
6
by: Ron Brennan | last post by:
Good evening. <span id=fileList> <input type=hidden name=file id=file_0 value=Name/> </span> .... document.getElementById(fileList).childNodes The childNodes is giving me two children: 1)...
1
by: ason | last post by:
Hi, I just tried to replace a single XmlNode with several ChildNodes. When doing this with the following code i found out that if you get the ChildNodes with 'ChildNodes' - property the nodes...
1
by: chris yoker via DotNetMonster.com | last post by:
hiya, I have a function that replaces the nodenames in an xmlFile. I use a while loop.The problem is, if the element has no childNodes, then it isn't replaced.I want ALL the elements to be...
1
by: craigkenisston | last post by:
Hi, I'm pretty newbie on XML so I have this basic question. I have a node which has 5 ChildNodes : <RelatedLink> <DataUrl type="canonical">clickhere2.com/</DataUrl>...
1
by: yawnmoth | last post by:
Given an element ID, is there a way to figure out what index one would need to use in the parentNode's childNodes array to get at that element? For example... <body> <div id="parent"> <div...
5
by: Moses | last post by:
HI The Value for childNodes.length differs with mozilla and IE Is it problem with my coding..... I could not under stood............. The following is the details
2
by: milecimm | last post by:
Hi, I'm trying to loop through the nodes of my xml file. The info I need to get is located quite deep in about the fifth node but I want to incorporate in the output information that is located in my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.