note 39423 added to ref.domxml
| From: | ngc at rn2 dot php dot net | Date: | Wed, 28 Jan 2004 09:48:55 +0000 |
| Subject: | note 39423 added to ref.domxml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64301@lists.php.net to get a copy of this message | ||
Sorry, a bug in my code... I made the first version late at night, sorry!
The bug was in the "if ($ChildDomNode->has_child_nodes())" block, I didn't save
the data for the for the CildNode of the CildNodes. the bug has been fixed.
<?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())
{
$tmpArray = (getElementAttributes($ChildDomNode,$elementName,$attriName));
$nodeArray = array_merge($nodeArray, $tmpArray);
unset($tmpArray);
}// 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+39423
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39423&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39423&report=yes
Search -- http://master.php.net/manage/user-notes.php