jjbigfish Posted December 7, 2012 Share Posted December 7, 2012 I would like to parse this example.xml file using PHP, and output it to a CSV file. Any help would be appreciated. example.xml Quote Link to comment https://forums.phpfreaks.com/topic/271719-parsing-xml/ Share on other sites More sharing options...
Maq Posted December 7, 2012 Share Posted December 7, 2012 http://bit.ly/VskTyd Quote Link to comment https://forums.phpfreaks.com/topic/271719-parsing-xml/#findComment-1398121 Share on other sites More sharing options...
Barand Posted December 7, 2012 Share Posted December 7, 2012 (edited) Simplest way I can think of is <?php $fh = fopen('mycsv.csv', 'w'); $xml = simplexml_load_file('example.xml'); foreach ($xml->xpath('//App') as $app) { $data = array ( (string)$app['id'], (string)$app['action'], (string)$app['ref'], (string)$app->BaseVehicle['id'], (string)$app->EngineBase['id'], (string)$app->Qty, (string)$app->PartType['id'], (string)$app->MfrLabel, (string)$app->Part ); fputcsv($fh, $data); } fclose($fh); ?> Edited December 7, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/271719-parsing-xml/#findComment-1398159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.