W3C DOM XPath

load(XML_FILE); // setup XPath $xpath = new DOMXPath($doc); // iterate over all employee elements $employees = $xpath->query("//employee[@no>1 and role!='Intern']", $doc); foreach($employees as $employee) { // find attribute no $no = $xpath->query("@no", $employee)->item(0)->nodeValue; // find sub elements name and role $name = $xpath->query("name/text()", $employee)->item(0)->nodeValue; $role = $xpath->query("role/text()", $employee)->item(0)->nodeValue; // print echo "\r\n"; echo "\r\n"; echo "\r\n"; echo "\r\n"; echo "\r\n"; } ?>
No Name Role
$no$name$role