I need some help with the following: I wrote a script to get a response from a webservice and then to save it in an XML file on my server. This is the structure of the XML file:
<xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetCatalogResponse xmlns="http://tempuri.org/">
<GetCatalogResult>
<Products>
<Product>
<Code>1234</Code>
<Name>product name</Name>
<Category>some category</Category>
<Manufacturer>manufacturer</Manufacturer>
<Price>100</Price>
<Stock>1</Stock>
</Product>
</Products>
</GetCatalogResult>
</GetCatalogResponse>
</soap:Body>
</soap:Envelope>
I'm using this script to convert the XML file to CSV:
$filexml='filename.xml';
if (file_exists($filexml)) {
$xml = simplexml_load_file($filexml);
$f = fopen('filename.csv', 'w');
// I only need the CSV to contain two columns, the product code and the corresponding price
foreach($xml->Products->Product as $Product) {
$values = array("Code" => $Product->Code, "Price" => $Product->Price);
fputcsv($f, $values,',','"');
}
fclose($f);
}
The problem is that there is no output in the CSV file, my guess is that there is a problem with the namespaces, but I can't get around it, even though I've read all the solutions given here to similar problems.
Any help will be greatly appreciated.