note 68185 added to ref.dom

From: Date: Mon, 17 Jul 2006 15:48:52 +0000
Subject: note 68185 added to ref.dom
Groups: php.notes 
Request: Send a blank email to php-notes+get-114849@lists.php.net to get a copy of this message
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; } } ---- Server IP: 66.163.161.117 Probable Submitter: 129.79.86.3 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.dom.php Edit -- http://master.php.net/note/edit/68185 Del: integrated -- http://master.php.net/note/delete/68185/integrated Del: useless -- http://master.php.net/note/delete/68185/useless Del: bad code -- http://master.php.net/note/delete/68185/bad+code Del: spam -- http://master.php.net/note/delete/68185/spam Del: non-english -- http://master.php.net/note/delete/68185/non-english Del: in docs -- http://master.php.net/note/delete/68185/in+docs Del: other reasons-- http://master.php.net/note/delete/68185 Reject -- http://master.php.net/note/reject/68185 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114849) next »