note 68185 deleted from ref.dom by didou

From: Date: Sat, 30 Dec 2006 03:01:12 +0000
Subject: note 68185 deleted from ref.dom by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121034@lists.php.net to get a copy of this message
Note Submitter: com dot yahoo at adjwilli ---- Here's a function to get a node by attribute. I thought I'd post it to save other people from reinventing the wheel too. $attr is the attribute the node should have, $nodeID is the value you're looking for in that attribute, and $xmldoc is the doc you're looking in. I'd also welcome suggestion to make this function more efficient. function getNodeByAttr ($attr,$nodeID,$xmldoc) { if ($xmldoc->hasChildNodes()) { $children = $xmldoc->childNodes; foreach($children as $node) { if ($node->hasAttributes()) { $attributes = $node->attributes; foreach ($attributes as $attribute) { if (($attribute->name == $attr) && ($attribute->value == $nodeID)) { return $node; } else { if (getNodeByAttr($attr,$nodeID,$node)) { return getNodeByAttr($attr,$nodeID,$node); } } } } else { if (getNodeByAttr($attr,$nodeID,$node)) { return getNodeByAttr($attr,$nodeID,$node); } } } } else { return null; } }

« previous php.notes (#121034) next »