473,480 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem getting nested xml nodes with C#, .NET 2.0 (XmlDocument)

I am trying to pull out some nested XML using C# and XMLReader.

Can't seem to extract the "Items" for each "Product" when i loop
through file, i can loop over the "Product" notes just fine but
everytime i perform a nested loop over the "Items" list i keep every
item on the file listed for each "Product".
Is there an easy approach to get the related Items for each Product ID
instead of all the Items everytime?

my xml file looks something like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<Products>
<Product>
<ProductID>12</ProductID>
<Items>
<Item>
<ItemID>1</ItemID>
<Part>Some Great Part</Part>
</Item>
<Item>
<ItemID>2</ItemID>
<Part>Extra Part</Part>
</Item>
</Items>
</Product>
<Product>
<ProductID>13</ProductID>
<Items>
<Item>
<ItemID>3</ItemID>
<Part>Missing Part</Part>
</Item>
</Items>
</Product>
</Products>

By the way i accidentally posted this question in the wrong group
earlier so i apologize in advance if anyone has tripped over already.

Thanks in for any guidance...

Nov 9 '06 #1
2 2404
Hi,

Your XML looks like a dataset.

I would just try this one,

DataSet ds = ds.ReadXML("MyPath");

And than go through the tables, that one is much easier than the node
reader.
(use integer indexers not names).

I hope this helps,

Cor
"th3dude" <gn*****@gmail.comschreef in bericht
news:11**********************@e3g2000cwe.googlegro ups.com...
>I am trying to pull out some nested XML using C# and XMLReader.

Can't seem to extract the "Items" for each "Product" when i loop
through file, i can loop over the "Product" notes just fine but
everytime i perform a nested loop over the "Items" list i keep every
item on the file listed for each "Product".
Is there an easy approach to get the related Items for each Product ID
instead of all the Items everytime?

my xml file looks something like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<Products>
<Product>
<ProductID>12</ProductID>
<Items>
<Item>
<ItemID>1</ItemID>
<Part>Some Great Part</Part>
</Item>
<Item>
<ItemID>2</ItemID>
<Part>Extra Part</Part>
</Item>
</Items>
</Product>
<Product>
<ProductID>13</ProductID>
<Items>
<Item>
<ItemID>3</ItemID>
<Part>Missing Part</Part>
</Item>
</Items>
</Product>
</Products>

By the way i accidentally posted this question in the wrong group
earlier so i apologize in advance if anyone has tripped over already.

Thanks in for any guidance...

Nov 10 '06 #2
Hey Cor,

Thanks for the reply.

Yes i've moved to trying this with a dataset, but i cannot get the
Parent/Child part working where i can associate the Products and Items
correctly (the same way they are nested)

It just reads them out in groups.

Any advice would be great!

Thanks again!

Cor Ligthert [MVP] wrote:
Hi,

Your XML looks like a dataset.

I would just try this one,

DataSet ds = ds.ReadXML("MyPath");

And than go through the tables, that one is much easier than the node
reader.
(use integer indexers not names).

I hope this helps,

Cor
"th3dude" <gn*****@gmail.comschreef in bericht
news:11**********************@e3g2000cwe.googlegro ups.com...
I am trying to pull out some nested XML using C# and XMLReader.

Can't seem to extract the "Items" for each "Product" when i loop
through file, i can loop over the "Product" notes just fine but
everytime i perform a nested loop over the "Items" list i keep every
item on the file listed for each "Product".
Is there an easy approach to get the related Items for each Product ID
instead of all the Items everytime?

my xml file looks something like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<Products>
<Product>
<ProductID>12</ProductID>
<Items>
<Item>
<ItemID>1</ItemID>
<Part>Some Great Part</Part>
</Item>
<Item>
<ItemID>2</ItemID>
<Part>Extra Part</Part>
</Item>
</Items>
</Product>
<Product>
<ProductID>13</ProductID>
<Items>
<Item>
<ItemID>3</ItemID>
<Part>Missing Part</Part>
</Item>
</Items>
</Product>
</Products>

By the way i accidentally posted this question in the wrong group
earlier so i apologize in advance if anyone has tripped over already.

Thanks in for any guidance...
Nov 10 '06 #3

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

Similar topics

3
25404
by: binnyva | last post by:
Hi everyone. I just made a JavaScript program to read a RSS feeds and display it in a HTML file. The script - Jasfer or JAvaScript FEed Reader - is available at...
4
2356
by: Pavils Jurjans | last post by:
Hello, I am interested in getting the XML contents as text between two XML elements that I know follow each other. They could be in completely different levels, but in XML file the first is...
2
10658
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
1
3059
by: Hazz | last post by:
I have 5 tables in SQL Server. Each with the following design and a sample chain of the relationships from the root (WRL - World) UUS is the 'Code' of the first table and it is the 'Parent' value...
1
1581
by: TT (Tom Tempelaere) | last post by:
Hi there, I load an Xml document into an XmlDocument object. I look up some nodes using SelectNodes/SelectSingleNode, and I modify the InnerText property. After this I call the XmlDocument.Save...
4
1677
by: Paul Bromley | last post by:
I thought that XMLTextReader would be simple to use, but I have run into problems with it! I seem to have great difficulty extrcting the text of specific elements from a very simple XML file. I...
4
6671
by: loretta | last post by:
I have data within an xml tag that is being truncated when being read into a javascript variable. On Firefox, I am only getting up to 4096 characters. On IE, I am getting 31324 characters. I can...
1
1257
by: JustinLee | last post by:
Hi, I have a small app that saves and loads data in XML format. Basically I have 2 methods. They each load data from a different XML documents. They both load data the same way. Everything works...
14
1641
by: anju458 | last post by:
Hi, I had a function to compare two XML files within a project . Now I need to change that into a commandline exe in such a way that it whouls accept two params from the Command line. I have...
0
7044
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
6908
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
7045
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,...
1
6741
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
6944
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...
1
4782
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...
0
4483
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.