convert complex xml feed to csv using php

i have a xml data feed which needs to be accessed using curl. i tried to get the curl output and use the XMLReader to read each node but it didnt work. Because when i loaded the feed using curl it takes around 1-2 minutes because its quite big.so what i thought was to download the feed to my server and convert it to csv and upload it to my database. so i can use it with a cron to keep my database updated.i found this code which seems to work fine in normal xml feeds but it doesn't seem to be working for my feed.in this feed\[code\]<cars><car> <color>blue</color> <price>2000</price></car><car> <color>red</color> <price>10000</price></car> <car> <color>black</color> <price>5000</price></car></cars>\[/code\]when i use the below code it works.\[code\]$filexml='cars.xml';if (file_exists($filexml)) { $xml = simplexml_load_file($filexml);$f = fopen('cars.csv', 'w');foreach ($xml->car as $car) { fputcsv($f, get_object_vars($car),',','"');}fclose($f);}\[/code\]but when it comes to the below feed how do i change the above code to add the model, pictures,images,types.... to the csv?\[code\] <cars><car> <color>blue</color> <price>2000</price> <model /> <pictures> <image>1.jpg</image> <image>2.jpg</image> </pictures> <type> <bodykit>yes</bodykit> <turbo>no</turbo> <sound>surround</sound> </type></car><car> <color>red</color> <price>10000</price><model>GTX</model> <pictures> <image>5.jpg</image> </pictures> <type> <bodykit>yes</bodykit> <turbo>no</turbo> <sound>no</sound> </type> </car> <car> <color>black</color> <price>5000</price> <model>GTX</model> <pictures> <image>5.jpg</image> <image>8.jpg</image> </pictures> <type> <bodykit>yes</bodykit> <turbo>no</turbo> <sound>surround</sound> </type></car></cars>\[/code\]any help or thoughts will be appreciated...
 
Back
Top