I have the following issue. I have an XML file with the following structure:
<?xml version="1.0" encoding="utf-8"?>
<Stocproduse>
<record ProdusId="1622" Stoc="11.00"/>
<record ProdusId="1632" Stoc="11.00"/>
</Stocproduse>
I'm trying to use the following PHP script to insert the data into a csv file, but it doesn't work:
$filexml='/var/www/html/site.com/Stoc_produse.xml';
$xml = simplexml_load_file($filexml);
$f = fopen('/var/www/html/site.com/stoc_produse.csv', 'w');
foreach($xml->record as $record){
$values = array("ProdusId" => $record->ProdusId, "Stoc" => $record->Stoc);
fputcsv($f, $values,','," ");
}
fclose($f);
However, if I convert the XML structure in the following way it works:
<?xml version="1.0" encoding="utf-8"?>
<Stocproduse>
<record>
<ProdusId>1622</ProdusId>
<Stoc>11.00</Stoc>
</record>
<record>
<ProdusId>1623</ProdusId>
<Stoc>11.00</Stoc>
</record>
</Stocproduse>
Does anyone have any idea what modifications I should make to the php script in order for it to work with the first xml structure? Any help will be greatly appreciated.
Thank you.