note 39414 deleted from ref.domxml by irchtml

From: Date: Sat, 17 Apr 2004 08:17:21 +0000
Subject: note 39414 deleted from ref.domxml by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-68233@lists.php.net to get a copy of this message
Note Submitter: ngc(dontSpamMe)rapanden(SpamOFF)dk ---- This function is a modifide version of "PrintDomTree" made by "bart at mediawave dot nl" and "phpdocs at pointbeing dot net" Thats findes the values of a specified attributes of a specifed element and returns them as an array. <?php function getElementAttributes($DomNode,$elementName,$attriName) { if ($ChildDomNode = $DomNode->first_child()) { while($ChildDomNode) { if ($ChildDomNode->node_type() == XML_ELEMENT_NODE) { if($ChildDomNode->node_name() == $elementName) { if ($ChildDomNode->has_attributes()) { $Array = $ChildDomNode->attributes(); foreach ($Array AS $DomAttribute) { if($DomAttribute->name() == $attriName) { $nodeArray[] = $DomAttribute->value(); } }// foreach ($Array AS $DomAttribute) }//if ($ChildDomNode->has_attributes()) } if ($ChildDomNode->has_child_nodes()) { if (getElementAttributes($ChildDomNode,$elementName,$attriName)){} }// if ($ChildDomNode->has_child_nodes()) }//if ($ChildDomNode->node_type() == XML_ELEMENT_NODE) $ChildDomNode = $ChildDomNode->next_sibling(); }//while($ChildDomNode) return $nodeArray; }//if ($ChildDomNode = $DomNode->first_child()) } $file = "test3.xml"; $element = "pb"; $att = "id"; $DomDocument = domxml_open_file($file); $RootDomNode = $DomDocument->document_element(); $array = getElementAttributes($RootDomNode,$element,$att); echo "<pre>"; print_r($array); echo "</pre>"; ?>

« previous php.notes (#68233) next »