I have an XML file that looks something like this
<Root fileType="hierarchy" schema_version="1.1.1">
<group id="978407" subtype="Web Section">
<attribute definition_id="1294" is_name="true" type="text">
<data language="English" label="Web Section">3.6V Drill Drivers</data>
</attribute>
<group id="884622" subtype="Product">
<attribute definition_id="11" is_name="true" is_identifier="true" type="text">
<data language="English" label="Product Name">Bosch IXO IV Cordless Screwdriver 3.6V (1.5Ah)</data>
</attribute>
<attribute definition_id="15" type="text">
<data language="English" label="Brand">Bosch</data>
</attribute>
<attribute definition_id="18" type="text">
<data language="English" label="Model">IXO IV</data>
</attribute>
I'm wanting to parse it and extract such things as the value of "Model" (for the sake of clarity the value would be 'IXO IV' or the value of the 'id' attribute (978407 or 884622).
I want this done using a foreach loop and the values added to a csv.
so far my PHP looks like this
<?php
// xml source
$filexml='3-6v-drill-drivers.xml';
if (file_exists($filexml))
{
// headers variable
$headers = array("sku", "attribute_set_code", "categories","name", "description","short_description","weight","speed","model","url_key","image","additional_images","accessories","alternatives");
//xml object var
$drillData = simplexml_load_file($filexml) or die("Me no understand");
$products = $drillData->xpath('/Root/group/group[@subtype="Product"]/attribute[@*]');
//create the file
$fh = fopen("testtttt.csv", "w");
//create headers
fputcsv($fh, $headers);
//itterate through object
foreach ($products as $product)
{
$put_arr = array($product->data['label="Model"'],$product->data['label="Brand"']);
fputcsv($fh, $put_arr);
}
fclose($fh);
}
?>
It's not working... I've also tried defining it using xpath within the loop ($put_arr = array($product->xpath('/data/[@label="Brand"]'), also to no avail.