note 51469 deleted from ref.dom by didou
| From: | didou@php.net | Date: | Sat, 30 Dec 2006 02:54:52 +0000 |
| Subject: | note 51469 deleted from ref.dom by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121030@lists.php.net to get a copy of this message | ||
Note Submitter: shruti224 at yahoo dot com
----
my bad..its not an attribute ..its a text element node so if one checks for that, it can be easily
corrected.
Wrote the corrected function. I hope it takes care of all conditions. If someone finds any issues
with it, I would be glad to know about it.
function readXml($domnode, &$array)
{
$array_ptr = &$array;
$domnode = $domnode->firstChild;
while (!is_null($domnode))
{
switch ($domnode->nodeType)
{
case XML_TEXT_NODE: if(!(trim($domnode->nodeValue) == ""))
$array_ptr['cdata'] =
$domnode->nodeValue;
break;
case XML_ELEMENT_NODE:
$array_ptr = &$array[$domnode->nodeName][];
if ($domnode->hasAttributes() )
{
$attributes = $domnode->attributes;
foreach ($attributes as $index =>
$domobj)
{
$array_ptr[$domobj->name] =
$domobj->value;
}
}
break;
}
if ( $domnode->hasChildNodes() )
{
readXml($domnode, $array_ptr);
}
$domnode = $domnode->nextSibling;
}
}