PHP xpath query
Posted: Mon Dec 01, 2014 9:58 pm
Hi ,
I have an xml file which i use to retrieve product information from. I am able to get most of the data that i require except for its Specs. here is the part of php code. This php file was developed by another developer and it is bit broken so i have to fix it.
this code does not do anything really. I wish to echo the weight's value and unit from to below xml.
I have an xml file which i use to retrieve product information from. I am able to get most of the data that i require except for its Specs. here is the part of php code. This php file was developed by another developer and it is bit broken so i have to fix it.
Code: Select all
$products = $xml->xpath('//PRV');
foreach ($products as $product) {
$stats = getstats($product->xpath('//PRAT'));
$statskeys = array_keys($stats);
function getstats($stats)
{
$statsarray ="";
foreach ($stats as $PRAT) {
$statsarray[$PRAT['dictionary_entry']] = $PRAT->VALUE . " " . $PRAT->VALUE['unit'];
return $statsarray;
}
}
}Code: Select all
<PRV proid="100403" id="328928" name="1.347-705.0 WD 4.200">
<PRAT languagespecific="0" attrtype="ProductattributeTypeTechData" datatype="N" ProdID="328928" name="GEWICHT_OHNE_ZUBEHOER" product_number="13477050" dictionary_entry="Weight" dict_id="1911">
<VALUE nr="1" unit="kg" unit_id="3123" vo="" vo_id="">7,5</VALUE>
</PRAT>
</PRV>