Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    simplexml_load_string begginers question

    Hello all
    im using simplexml_load_string to convert xml string to object
    and then i go to each node by name following the node hierarchy for example
    if i have xml like to get c i just do
    PHP Code:
    $xml simplexml_load_string($req);
    print (
    $xml->a->b->c); 
    Code:
    <a>
      <b>
        <c>
        </c>
      </b>
    </a>
    but how can i get for example second or third <c> if i have something like this :
    Code:
    <a>
      <b>
        <c>
        </c>
         <c>
        </c>
          <c>
        </c>
      </b>
    </a>
    still using the xml object converted from simplexml_load_string
    Thanks

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    <a> ... </a> will be the name, so you'll be starting with <b> ... </b>:
    PHP Code:
    $xml simplexml_load_string$req );
    foreach ( 
    $xml->b->as $c )
    {
        echo 
    $c"\n";


  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the response
    is there any method to avoid looping , maybe by index ( [0],[1],[2] ...)
    im not restrict to simplexml_load_string i can use other method also
    Thanks


  •  

    Posting Permissions

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