简体   繁体   English

使用API​​的XML到CSV转换器

[英]XML to CSV converter using API

I want to convert my XML file into CSV file but i want to use any tool who convert it automatically and i can pass input parameter using its API.I don't want to use any script to directly convert XML to csv. 我想将XML文件转换为CSV文件,但是我想使用任何自动将其转换的工具,并且可以使用其API传递输入参数。我不想使用任何脚本将XML直接转换为csv。 Is there any way to perform this? 有什么方法可以执行此操作吗?

Use PHP_curl.... 使用PHP_curl ...

Here is the code.. 这是代码。

<?php
$filexml="formdata.xml";
 if (file_exists($filexml))            {
   $xml = simplexml_load_file($filexml);
    $f = fopen('invoice.csv', 'w');
    createCsv($xml, $f);
    fclose($f);
  }
function createCsv($xml,$f)
{
 $arr1 = array('col1','col2'...); 
 fputcsv($f, $arr1 ,',','"');
     foreach ($xml->record as $item) 
    {
       $hasChild = (count($item->record) > 0)?true:false;

    if( ! $hasChild)
    {
    //item is xml tag name 
        $put_arr = array($item->company_name); 

     fputcsv($f, $put_arr ,',','"');

   }
    else
    {
     createCsv($item, $f);
    }
 }

}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM