note 39414 added to ref.domxml

From: Date: Tue, 27 Jan 2004 22:05:15 +0000
Subject: note 39414 added to ref.domxml
Groups: php.notes 
Request: Send a blank email to php-notes+get-64286@lists.php.net to get a copy of this message
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>"; ?> ---- Manual Page -- http://www.php.net/manual/en/ref.domxml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39414 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39414&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39414&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64286) next »