SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php and xml problem

    dear everyone, my problem is that i made xml nodes in variable and then i tried to explode it
    my xml is
    Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <channel>
      <request>
        <username>username</username>
        <request_id>11111</request_id>
        <request_type>request_type</request_type>
    
        <reply_table>
          <mydata>
            <first_td>0001AA</first_td>
            <second_td>N</second_td>
            <third_td>N</third_td>
            <fourth_td />
            <fifth_td>SU</fifth_td>
            <sixth_td>     HELP DESK</sixth_td>
          </mydata>
          <mydata>
            <first_td>0009IO</first_td>
            <second_td>N</second_td>
            <third_td>N</third_td>
            <fourth_td />
            <fifth_td>SU</fifth_td>
            <sixth_td>     KARIM MOHA</sixth_td>
          </mydata>
          <mydata>
            <first_td>0099PO</first_td>
            <second_td>N</second_td>
            <third_td>N</third_td>
            <fourth_td />
            <fifth_td>SU</fifth_td>
            <sixth_td>     KAMAL AHME</sixth_td>
          </mydata>
         
        </reply_table>
      </request>
      <request>
        <username>username</username>
        <request_id>11111</request_id>
        <request_type>request_type</request_type>
        <reply_table>
          <mydata>
            <first_td>0001AA</first_td>
            <second_td>N</second_td>
            <third_td>N</third_td>
            <fourth_td />
            <fifth_td>SU</fifth_td>
            <sixth_td>     HELP DESK</sixth_td>
          </mydata>
          <mydata>
            <first_td>0009IO</first_td>
            <second_td>N</second_td>
            <third_td>N</third_td>
            <fourth_td />
            <fifth_td>SU</fifth_td>
            <sixth_td>     KARIM MOHA</sixth_td>
          </mydata>
        </reply_table>
      </request>
    </channel>
    i want to explode it using the tag <request>, i made it by using for each

    Code:
    $dom= new DOMDocument();
    $dom-> loadXML($xmlo);
    
    $counter=1;
    $channel=$dom->getElementsByTagName("channel");  // first node of xml
    $request=$dom->getElementsByTagName("request");// sub node of xml
    foreach( $request as $data_result)
    {
    /// code goes here
    // exploding < mydata>inside the for each of request
    
    }
    the problem is in the nodes <mydata> and its inner nodes,
    example: the node <first_td> exists 3 times in first request and 2 times in second request, but when I tried to explode it by using for each loop, it shows the 5 nodes at same time,
    so how to solve this

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    What is it that you're actually trying to do? "exploding" isn't a very useful term.

    Do you want to loop over all of the <request> elements, and for each of those loop over their <mydata> elements (which are inside one <reply_table> for each <request>) and do something with the <something_td> elements inside?
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    What is it that you're actually trying to do? "exploding" isn't a very useful term.

    Do you want to loop over all of the <request> elements, and for each of those loop over their <mydata> elements (which are inside one <reply_table> for each <request>) and do something with the <something_td> elements inside?
    i made for each loop to explode the node <request> and it is exploding well without repeat , but its inner nodes <mydata> are fully displayed for all requests, it need to make it per request.

    notice that the for each loop for <mydata> is insed the for each loop of <request>...

    how to make for each as array to get request and my data per request not getting all mydata in a time???

    got it or you need to explain more??

    thanks for your help inadvance


Bookmarks

Posting Permissions

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