note 41578 deleted from function.domelement-get-elements-by-tagname by didou
| From: | didou@php.net | Date: | Tue, 02 Nov 2004 11:20:02 +0000 |
| Subject: | note 41578 deleted from function.domelement-get-elements-by-tagname by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79492@lists.php.net to get a copy of this message | ||
Note Submitter: azzra
----
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.