I am parsing xml using simplexml_load_string like this :
$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 but if a node appears in the xml multiple times it only grabs it once. Can someone please help me understand how I would write a foreach loop specifically for the Description node?
You are only referring to one instance of each
SimpleXMLObject.For example
$xml->Date[0]refers to the first occurence of a Date object only. To print all Date objects you need toloop through them
Alternatively, you could use the
childrenfunction: