Results 1 to 6 of 6

Thread: XML Child Nodes 'loops' [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Question XML Child Nodes 'loops' [RESOLVED]

    Hi guys,

    I have a problem which supposedly is easy to fix but I simply can't make it happen. So I hope someone can help me. I'll try to explain my problem as clearly as possible.

    I have a bunch of XML's that need to be put into an SQL database. One XML represents all orders for a certain department of a store. The problem (for me) is that in one XML there can be (and are) multiple orders (called distributions in my case.) The XML looks as follows (truncated):

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <order><process_id>322867</process_id>
    <key1>RET</key1>
    <key2>40_134985</key2>
    <currency_code>EUR</currency_code>
    <inv_type>Gold Standard CM</inv_type>
    
    <----Truncated part because it would become very long--->
    
    <distributions>
    <distribution>
    <dist_key>BIP            </dist_key>
    <dist_type>ITEM</dist_type>
    <dist_amount>16.52</dist_amount>
    <dtax_code>2</dtax_code>
    <dtax_rate>0.19</dtax_rate>
    <dist_segm2>840</dist_segm2>
    <dist_segm3>8001</dist_segm3>
    <dist_segm4>BIP</dist_segm4>
    </distribution>
    <distribution>
    <dist_key>OPSLAG         </dist_key>
    <dist_type>ITEM</dist_type>
    <dist_amount>1.38</dist_amount>
    <dtax_code>2</dtax_code>
    <dtax_rate>0.19</dtax_rate>
    <dist_segm2>840</dist_segm2>
    <dist_segm3>8001</dist_segm3>
    <dist_segm4>OPSLAG</dist_segm4>
    </distribution>
    </distributions>
    So in this example I have two 'distributions'. Now I can get all data out of the XML fine, which I do like this:

    get xml data Code:
    1. awsFeed = XDocument.Load(fileName)
    2.  Dim orders = From order In awsFeed...<order> _
    3.      Select process_id = order.Element("process_id").Value, _
    4.      trx_date = order.Element("trx_date").Value, _ (etc.. etc..)
    However, in this case my SQL input would have to result in 2 entries, because there are 2 orders. Both entries would have the same data, except for different entries. I know how to post to SQL, that's not the problem. My real problem is, how do I 'loop' it through the XML. I think i'm looking for something like:

    Possible solution? Code:
    1. For each 'distribution' in orders -> put into array.

    Or something like that. After that I could query the array and put it in the database. I hope I'm making it clear enough. If anyone could help me I would be so grateful because I've been stuck on this for days now and I although I find many tutorials, I don't seem to understand any of them, so if anyone could explain it in my own code that would be awesome, thank you in advance.
    Last edited by Booster77; Jun 7th, 2011 at 03:49 AM. Reason: [RESOLVED]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width