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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • th3dude

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

  • Cor Ligthert [MVP]

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

    Hi,

    Your XML looks like a dataset.

    I would just try this one,

    DataSet ds = ds.ReadXML("MyP ath");

    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" <gnothom@gmail. comschreef in bericht
    news:1163107686 .638053.139660@ e3g2000cwe.goog legroups.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...
    >

    Comment

    • th3dude

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

      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("MyP ath");
      >
      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" <gnothom@gmail. comschreef in bericht
      news:1163107686 .638053.139660@ e3g2000cwe.goog legroups.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...

      Comment

      Working...