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

T

th3dude

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...
 
C

Cor Ligthert [MVP]

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
 
T

th3dude

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top