php - How have foreach loop with this simplexml_load_string -


i parsing xml using simplexml_load_string :

 $xml = simplexml_load_string($response);          echo '{'.             '"date":"'.$xml->date[0].'",'.             '"description":"'.$xml->shiptos->shipto->shippinggroups->shippinggroup->orderitems->orderitem->description[0].'",'.              '"track":"'.$xml->shipments->shipment->track[0].'"'.             '}';  

this works ok if node appears in xml multiple times grabs once. can please me understand how write foreach loop description node?

you referring 1 instance of each simplexmlobject. example $xml->date[0] refers first occurence of date object only. print date objects need loop through them

foreach( $xml->date $date ){    print (string)$date; } 

alternatively, use children function:

foreach( $xml->children('date') $date ){    print (string)$date; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -