note 25964 deleted from function.domxml-xmltree by sobak
| From: | sobak@php.net | Date: | Tue, 22 Nov 2016 03:39:48 +0000 |
| Subject: | note 25964 deleted from function.domxml-xmltree by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207389@lists.php.net to get a copy of this message | ||
Note Submitter: nutbar at innocent dot com
----
Same concept as previous function, except uses node names as key items in the arrays. This function
may prove a bit more useful than the previous one:
function domxml_xmlarray($branch) {
$object = array();
$objptr = &$object;
$branch = $branch->first_child();
while ($branch) {
if (!($branch->is_blank_node())) {
switch ($branch->node_type()) {
case XML_TEXT_NODE: {
$objptr['cdata'] = $branch->node_value();
break;
}
case XML_ELEMENT_NODE: {
$objptr = &$object[$branch->node_name()][];
break;
}
}
if ($branch->has_child_nodes()) {
$objptr = array_merge($objptr, domxml_xmlarray($branch));
}
}
$branch = $branch->next_sibling();
}
return $object;
}
Usage is identical to the previous function.