note 30026 deleted from function.domelement-get-attribute-node by didou

From: Date: Sat, 18 Jun 2005 16:22:55 +0000
Subject: note 30026 deleted from function.domelement-get-attribute-node by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-90624@lists.php.net to get a copy of this message
Note Submitter: Damian De Pilla (DEPI) ---- 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

« previous php.notes (#90624) next »