note 61254 deleted from ref.domxml by bjori
| From: | bjori@php.net | Date: | Tue, 17 Apr 2007 09:23:27 +0000 |
| Subject: | note 61254 deleted from ref.domxml by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125495@lists.php.net to get a copy of this message | ||
Note Submitter: junk at gieson dot com
----
### Moderator:
### This is a very slight tweak to to the dom_to_simple_array function posted earliers by jas at uci
dot edu. I recommend just editing the previous post rather than posting the function again.
---------------------------------
The previously posted dom_to_simple_array function has a slight error, which prevents PHP from
processing if there are attributes present.
The line that reads:
$attributes = $domnode->attributes();
... should read:
$attributes = $domnode->attributes;
---------------------------------
Here is the full code again with the correction:
function dom_to_simple_array($domnode, &$array) {
$array_ptr = &$array;
$domnode = $domnode->firstChild;
while (!is_null($domnode)) {
if (! (trim($domnode->nodeValue) == "") ) {
switch ($domnode->nodeType) {
case XML_TEXT_NODE: {
$array_ptr['cdata'] = $domnode->nodeValue;
break;
}
case XML_ELEMENT_NODE: {
$array_ptr = &$array[$domnode->nodeName][];
if ($domnode->hasAttributes() ) {
$attributes = $domnode->attributes;
if (!is_array ($attributes)) {
break;
}
foreach ($attributes as $index => $domobj) {
$array_ptr[$index] = $array_ptr[$domobj->name] = $domobj->value;
}
}
break;
}
}
if ( $domnode->hasChildNodes() ) {
dom_to_simple_array($domnode, $array_ptr);
}
}
$domnode = $domnode->nextSibling;
}
}