I'm trying to find out if a DOM node has children nodes that have a certain name
$yes = false;
foreach($el->childNodes as $node){
if($node->nodeName == 'foo'){
$yes = true;
}
}
Can I do this without iterating over the node list?
There a hasChildNodes
function but it doesn't accept any node name argument :(
You can use XPath
$xpath = new DOMXPath($domDocument);
$elements = $xpath->query('/parentName/childName');
if ($elements->length) {
// has child elements
}