Error: Looping through an xml twice instead on of once.

Last post 07-06-2009 2:05 AM by kavita_khandhadia. 6 replies.

Sort Posts:

  • Error: Looping through an xml twice instead on of once.

    05-14-2009, 3:18 PM
    • Member
      12 point Member
    • penkye
    • Member since 03-11-2009, 1:33 PM
    • Posts 22

    Hi All,

             I just stampled accross this weired behavior trying to loop through an xml file by selecting the appropriate nodes. I don't seem to understand why it does the whole for loop twice. Any help greatly appreciated.

    Dim xmlDoc As New XmlDataDocument

    Dim m_nodelist As XmlNodeList

    xmlDoc.Load("D:\website\apphtml\da_beta\xml\" + iCookie + ".xml")

    m_nodelist = xmlDoc.SelectNodes("/cart_item/item")

    Dim node As XmlNode = xmlDoc.SelectSingleNode("/cart_item/item")

    For Each node In m_nodelist

    StockCode = node("part_no").InnerText

    Response.Write(StockCode)

    Next

    And i get this from the loop:

    N1005176
    N1005177
    N1005178
    N1005179
    Sales Order Posting Successfull
    Sales Order: 076436N1005176
    N1005177
    N1005178
    N1005179
    Sales Order Posting Successfull
    Sales Order: 076437

    xml file:

    <cart_item>
      <item>
        <CustID>734631</CustID>
        <part_no>N1005176</part_no>
        <prod_desc>Mobile Double Drawer</prod_desc>
        <Qty>1</Qty>
        <price>$49.92</price>
        <isize>Gray</isize>
        <icolor />
        <irecnum>135924</irecnum>
        <date>5/12/2009 2:11:25 PM</date>
        <subtotal>49.92</subtotal>
      </item>
      <item>
        <CustID>734631</CustID>
        <part_no>N1005177</part_no>
        <prod_desc>Storage Lockers Single Tier</prod_desc>
        <Qty>1</Qty>
        <price>$147.14</price>
        <isize>Dove Grey</isize>
        <icolor>
        </icolor>
        <irecnum>135816</irecnum>
        <date>5/12/2009 2:11:36 PM</date>
        <subtotal>147.14</subtotal>
      </item>

      </item>
    </cart_item>

  • Re: Error: Looping through an xml twice instead on of once.

    05-20-2009, 5:28 AM

    Hi penkye ,

    penkye:
    I don't seem to understand why it does the whole for loop twice

    There are two item nodes in this xml file. The xpath ("/cart_item/item") indicate that to fetch all item nodes under cart_item node. So loop twice.

     


    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
  • Re: Error: Looping through an xml twice instead on of once.

    07-02-2009, 11:47 AM
    • Member
      12 point Member
    • penkye
    • Member since 03-11-2009, 1:33 PM
    • Posts 22

    Hi Samu, I tried your suggestion but it some how still loops twice through the xml file. I'm not exactly sure what to do but i do well any suggestions or different approach to my problem. 

    Thanks.

  • Re: Error: Looping through an xml twice instead on of once.

    07-03-2009, 5:33 AM

    Provide 2 things here...ur input xml and wot out put u need from that xml


    Please mark this post as Answer if it is of help to you!

    " Every wall is a door..! "
  • Re: Error: Looping through an xml twice instead on of once.

    07-03-2009, 10:34 AM
    • Member
      12 point Member
    • penkye
    • Member since 03-11-2009, 1:33 PM
    • Posts 22

    Hi kavita, i'm not at this point trying to input any more data into the xml. i have the data that i need already and need to pass it to a process that will read and input the data into our system. For some strange reason when it loops through the selection node (item) it sort of loops twice and i don't know why?

  • Re: Error: Looping through an xml twice instead on of once.

    07-03-2009, 10:49 AM
    • Member
      313 point Member
    • agr001
    • Member since 01-04-2003, 6:49 PM
    • Posts 67

    Remove this line... Dim node As XmlNode = xmlDoc.SelectSingleNode("/cart_item/item")


    And change the loop to

    For Each node as XmlNode In m_nodelist

    this should do the trick.  

  • Re: Error: Looping through an xml twice instead on of once.

    07-06-2009, 2:05 AM

    penkye:

    Hi kavita, i'm not at this point trying to input any more data into the xml. i have the data that i need already and need to pass it to a process that will read and input the data into our system. For some strange reason when it loops through the selection node (item) it sort of loops twice and i don't know why?

    Humm of course i know that,,,

    i mean to say That..

    whenu do this..

    xmlDoc.Load("D:\website\apphtml\da_beta\xml\" + iCookie + ".xml")

    u can get the xml input file by doing this

    string myXml = xmlDoc.DocumentElement.OuterXml.

    I wanted u to paste the myXml varibale result over here.. it wud be good if u do that..so that we can solve ur prob

     :)



    Please mark this post as Answer if it is of help to you!

    " Every wall is a door..! "
Page 1 of 1 (7 items)