I have used php 5.0 to convert xmx to cvs. Here "SimpleXML" reads an entire xml into an object that we can iterate through his properties.To write to the csv output file we will use "fputcsv". "fputcsv" formats a line as csv and writes it to the file.
Code of xml file (as the name "cars.xml") is here:
[xml]
<?xml version='1.0'?>
<cars>
<car>
<color>blue</color>
<price>100</price>
</car>
<car>
<color>red</color>
<price>300</price>
</car>
</cars>
[/xml]
Code of php to convert in cvs is:
[php]
<?
$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);
}
?>
[/php]
I just want to mention I am just all new to blogs and seriously savored this web blog. Almost certainly I’m planning to bookmark your site . You actually have remarkable well written articles. Thanks a lot for revealing your blog site.
ReplyDeletejLLyHc vrpvwvyruxiv, [url=http://jsocmljpihya.com/]jsocmljpihya[/url], [link=http://yhktdblniffp.com/]yhktdblniffp[/link], http://ygquhlqpilnt.com/
ReplyDelete