Мне нужна помощь в следующем: я написал скрипт, чтобы получить ответ от веб-службы, а затем сохранить его в файле XML на моем сервере. Это структура файла XML:
<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>
Я использую этот скрипт для преобразования файла XML в 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);
}
Проблема в том, что в файле CSV нет выходных данных, я предполагаю, что есть проблема с пространствами имен, но я не могу обойти ее, хотя я прочитал все решения, приведенные здесь, для аналогичных проблемы.
Любая помощь будет принята с благодарностью.