Better SimpleXML parsing method
I'd make heavier use of xpath:

$xml = simplexml_load_string($x); // assume XML in $x
$class = $xml-&gt;xpath("//type[@extension = 'doc']/../../@class")[0];
$icon = $xml-&gt;xpath("//type[@extension = 'doc']/../@icon")[0];
$description = $xml-&gt;xpath("//type[@extension = 'doc']/@description")[0];

echo "$class | $icon | $description";


My code requires PHP >= 5.4, for older versions, do:

$class = $xml-&gt;xpath("//type[@extension = 'doc']/../../@class");
$class = $class[0];


or...

list($class,) = $xml-&gt;xpath("//type[@extension = 'doc']/../../@class");