note 30026 added to function.domelement-get-attribute-node

From: Date: Tue, 04 Mar 2003 16:00:35 +0000
Subject: note 30026 added to function.domelement-get-attribute-node
Groups: php.notes 
Request: Send a blank email to php-notes+get-44831@lists.php.net to get a copy of this message
Is common try to get an attribute of an DomElement object type, and this object don't be DomElement type. This problem exist because when u try to list the count of children of a node, by DomNode->child_nodes() function, it give u DomElements and DomTexts objects. I think that this is bad... To resolve it problem, before u apply DomElement->get_attribute_node() function, u must be sure that this DomElement object type is really a DomElement and don't be a DomText object type. U can use this code to resolve it: /* count childs */ $child_count=$root->child_nodes(); //echo "I have ".$child_count." childs<BR>"; /* Array of childs */ $childs=$parent_element->child_nodes(); for( $i = 0 ; $i < $child_count ; $i++){ $var_attribute=$childs[$i]->attributes(); /* Now i verify if $childs[$i] is a DomElement or a DomText object type */ if( $var_attribute == NULL ){ /* Don't be a DomElement , it is a DomText object type */ continue; } /* Now $childs[$i] is a DomElement object type and u can use DomElement->get_attribute_node() function */ //var_dump($var_attribute); } Good Luck. ddepill1@ta.telecom.com.ar -- http://www.php.net/manual/en/function.domelement-get-attribute-node.php http://master.php.net/manage/user-notes.php?action=edit+30026 http://master.php.net/manage/user-notes.php?action=delete+30026 http://master.php.net/manage/user-notes.php?action=reject+30026

« previous php.notes (#44831) next »