Nu kom ik er niet meer uit.
Deze functie gebruik ik om een xml bestand om te zetten naar csv
function convertXmlToCsvFile($xml_file_input, $csv_file_output) {
$xml = simplexml_load_file($xml_file_input);
$output_file = fopen($csv_file_output, 'w');
$header = false;
foreach($xml as $key => $value){
if(!$header) {
fputcsv($output_file, array_keys(get_object_vars($value),',','"'));
$header = true;
}
fputcsv($output_file, get_object_vars($value),',','"');
}
fclose($output_file);
}
$doen = convertXmlToCsvFile(DOC_ROOT.'shopconnector/feeds/feed'.$_POST['id'].'import.xml',DOC_ROOT.'shopconnector/feeds/feed'.$_POST['id'].'import.csv');
Een xml die wel met de headers (veldnamen) in de xml als eerste regel word opgeslagen is bij deze wel goed:
<?xml version="1.0" encoding="utf-8"?>
<Products>
<Product>
<Product_ID>LI64MB520</Product_ID>
<Product_Name>Siemens iQ100 LI64MB520 Vlakscherm-afzuigkappen - Zilver</Product_Name>
<Product_URL>https://prf.hn/click/camref:1011l3rad/creativeref:1100l6935/destination:https://www.ao.nl/product/li64mb520-siemens-vlakscherm-afzuigkappen-zilver-39457-4.aspx?&WT.z_PT=MDA&WT.z_AT=Afzuigkappen&WT.z_BR=Siemens&WT.z_FT=Built%20In&WT.z_PC=LI64MB520_GY&WT.z_MT=Affiliate&WT.z_RTM=PHG&WT.srch=1</Product_URL>
<Image_Thumbnail_URL>http://media.ao.com/productafbeeldingen/klein/li64mb520_gy_siemens_afzuigkap_fr_s.jpg</Image_Thumbnail_URL>
<Image_Medium_URL>http://media.ao.com/productafbeeldingen/medium/li64mb520_gy_siemens_afzuigkap_fr_m_p.jpg</Image_Medium_URL>
<Image_Large_URL>http://media.ao.com/productafbeeldingen/groot/li64mb520_gy_siemens_afzuigkap_fr_l.jpg</Image_Large_URL>
<Price>248.00</Price>
<Description>Siemens iQ100 LI64MB520 Vlakscherm-afzuigkappen - Zilver</Description>
<Product_Category>Home & Garden > Kitchen & Dining > Kitchen Appliances > Range Hoods</Product_Category>
<Product_Type>Afzuigkappen</Product_Type>
<Category />
<Sub_Category />
<SKU>LI64MB520</SKU>
<Promo_Text />
<Previous_Price />
<Warranty>2 Jaren</Warranty>
<Brand>Siemens</Brand>
<Availability>In voorraad</Availability>
<Condition>Neu</Condition>
<Colour>Zilver</Colour>
<EAN_Code>4242003717851</EAN_Code>
<Height>175</Height>
<Width>598</Width>
<Depth>290</Depth>
<Delivery_Cost>0.0000</Delivery_Cost>
<Company_URL>https://prf.hn/click/camref:1011l3rad/creativeref:1100l6935/destination:http://www.ao.nl</Company_URL>
<Delivery_Time>2 Werkdagen</Delivery_Time>
<Energy_Efficiency_Class>B</Energy_Efficiency_Class>
<Promotions />
<Manufacturer>BSH</Manufacturer>
<GTIN_Code>4242003717851</GTIN_Code>
<Fit_Type>Ingebouwd</Fit_Type>
<Country>DEU</Country>
<Additional_ProductInformation />
<Payment_Method>Maestro – Visa - Visa Debit – Mastercard – Paypal</Payment_Method>
<Dimensions>(H)17,5 x (B)59,8 x (T)29,0</Dimensions>
<InStock>True</InStock>
</Product>
Maar bij deze niet. Bij deze zijn de headers leeg:
<products>
<product>
<sku>122470</sku>
<upc>045496521288</upc>
<product_name>Mario Kart 7 3DS</product_name>
<brand>Nintendo</brand>
<currency>EUR</currency>
<price>42.99</price>
<condition>new</condition>
<product_url>https://prf.hn/click/camref:1100l5eGG/creativeref:1101l32317/destination:https://www.coolblue.nl/product/122470/mario-kart-7-3ds.html</product_url>
<image_url>https://image.coolblue.nl/1024x1024/products/139591.jpg</image_url>
<free_shipping>yes</free_shipping>
<category>Games</category>
<product_type>Games</product_type>
<availability>2</availability>
<shipping_cost>0.00</shipping_cost>
<group>yes</group>
<reviewsaveragescore>9.8</reviewsaveragescore>
<reviewscount>19</reviewscount>
<coolblueskeuze>0</coolblueskeuze>
<delivery_time>Voor 23.59 uur besteld, morgen in huis.</delivery_time>
<categoryid>2053</categoryid>
</product>
Ik kan er dan niks mee de eerste 4 waarden zijn dan leeg ??
Hoe kan dit? en hoe is dit op te lossen?