note 41578 added to function.domelement-get-elements-by-tagname
| From: | azzra at rn2 dot php dot net | Date: | Thu, 15 Apr 2004 10:28:42 +0000 |
| Subject: | note 41578 added to function.domelement-get-elements-by-tagname | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68158@lists.php.net to get a copy of this message | ||
Here the way to get an element by an unique attribute.
This function return an element.
function get_element_by_unique_attribute($node, $tag) {
//if there are childs
if($childs= $node -> child_nodes()) {
//start looping
foreach($childs as $c) {
//check if this node is not a #text node
if($c -> type == XML_ELEMENT_NODE) {
//check the tag
if($c -> get_attribute('YOUR_ATTRIBUTE) == $tag) {
//found
return $c;
} else {
//we restart searching at the current node to avoid infinite looping
$a = get_element_by_unique_attribute($c, $tag);
}
}
}
return $a;
}
}
I hope this helps...
Thanks to nukebaghdad.
----
Manual Page -- http://www.php.net/manual/en/function.domelement-get-elements-by-tagname.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41578
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41578&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41578&report=yes
Search -- http://master.php.net/manage/user-notes.php