Hey PHP gurus...

I have a string with an XML file output stored to it. I need to parse that string and extract data to output into a CSV file. I was able to figure out how to accomplish this for the unique data items in the XML file, but not for the multiple products in the stream. There are multiple line items for each product so I have to loop through that some how, but I'm not clear on how.

This is the XML file:
<shipping-address>
<address1>123 Shipping Street</address1>
<address2 nil="true"></address2>
<city>Shippington</city>
<company nil="true"></company>
<country>Shippington Emirates</country>
<first-name>Steve</first-name>
<last-name>Shipper</last-name>
<phone>555-555-SHIP</phone>
<province>SH</province>
<zip>K2P0S0</zip>
<name>Steve Shipper</name>
</shipping-address>
<line-items type="array">
<line-item>
<fulfillment-service>manual</fulfillment-service>
<grams type="integer">5000</grams>
<price type="decimal">199.99</price>
<quantity type="integer">1</quantity>
<sku>SKU2006-001</sku>
<title>Sledgehammer</title>
<variant-id type="integer" nil="true"></variant-id>
<vendor nil="true"></vendor>
<name>Sledgehammer</name>
</line-item>
<line-item>
<fulfillment-service>manual</fulfillment-service>
<grams type="integer">500</grams>
<price type="decimal">29.95</price>
<quantity type="integer">1</quantity>
<sku>SKU2006-020</sku>
<title>Wire Cutter</title>
<variant-id type="integer" nil="true"></variant-id>
<vendor nil="true"></vendor>
<name>Wire Cutter</name>
</line-item>
</line-items>
<shipping-line>
<price type="decimal">10.00</price>
<title>Generic Shipping</title>
</shipping-line>
</order>


This the PHP that is working so far...
$cr = "\n";
$xml = new SimpleXMLElement($xmlString);

$email = trim($xml->email);
$address1 = trim($xml->{'shipping-address'}->address1);
$address2 = trim($xml->{'shipping-address'}->address2);
$city = trim($xml->{'shipping-address'}->city);
$company = trim($xml->{'shipping-address'}->company);
$country = trim($xml->{'shipping-address'}->country);
$name = trim($xml->{'shipping-address'}->name);
$phone = trim($xml->{'shipping-address'}->phone);
$state = trim($xml->{'shipping-address'}->province);
$zip = trim($xml->{'shipping-address'}->zip);

$data = $name.",".$email.",".$phone.",".$address1.",".$address2.",".$city.",".$company.",".$country.",".$sta te.",".$zip.",".$cr;



Ideas about how to create a loop to assign all the line items and add it to the data variable??

Thanks so much!!

Joe