xml - get child element using xpath and php -
i have sample xml file:-
<products> <product_id value="1"> <tab_id value="251"> <dist_region value="5" /> <dist_region value="10066" /> <dist_region value="10069" /> </tab_id> </product_id> </products> i trying tab_id child element using xpathand want result in set of child elements.
my expected output follows:-
dist_region,dist_region,dist_region
my xpath:-
$tab = $product->xpath('//tab_id/*'); can suggest xpath child elements? thanks.
the xpath tried works me. so, try next code:
$sxml = new simplexmlelement($xml); $xpath = $sxml->xpath('//tab_id/*'); $array = array(); foreach ($xpath $child) { $array[] = $child->getname(); } echo implode(',',$array); it gives desire output: dist_region,dist_region,dist_region.
been $xml xml file.
Comments
Post a Comment