You can try
$list = groupBy($xml, "WebCategory");
foreach ( $list['Mobiles'] as $product ) {
printf('<li>%s %s</li>', $product->Code, $product->Name);
}
Output
10000 HTC Wildfire S-A510E 10001 HTC Wildfire10002 Samsung Galaxy S310003 Samsung Galaxy S210004 Samsung Galaxy S110007 Apple Iphone 4S10008 Apple Iphone 3G10012 Sony Erricsson Satio
Function Used
function groupBy($xml, $categoryName) {
$xml = new \SimpleXMLElement($xml);
$category = array();
foreach ( $xml as $row ) {
$attr = $row->attributes();
if (! isset($attr->$categoryName)) {
trigger_error("$categoryName does not exist in XML");
break;
}
$category[(string) $attr->$categoryName][] = $attr;
}
return $category;
}
See live Demo