note 25781 deleted from function.xml-parse-into-struct by betz
| From: | betz@php.net | Date: | Wed, 31 Mar 2004 08:32:25 +0000 |
| Subject: | note 25781 deleted from function.xml-parse-into-struct by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67406@lists.php.net to get a copy of this message | ||
Note Submitter: ambi at gmx dot de
----
I tried the code of the xml_condense_children and figured out that it doesn't work if you have
2 or more children with similar tagname.
It should then leave them as children and not put only one as value.
Here you find the fixed code:
function xml_condense_tree($tree) {
if ($tree["children"]) {
unset($nodecounters);
$maxindex=0;
foreach ($tree['children'] as $index => $node) {
if (!isset($nodecounters[$node['tag']]))
$nodecounters[$node['tag']]=1;
else $nodecounters[$node['tag']]++;
$maxindex=$index>$maxindex ? $index:$maxindex;
}
foreach ($tree['children'] as $index => $node) {
if (isset($node['children'])) {
$tree['children'][$index] = xml_condense_tree($node);
} elseif (isset($node['value']) and !$node['attributes'] and
$nodecounters[$node['tag']]==1) {
$tree['values'][$node['tag']] = $node['value'];
unset($tree['children'][$index]);
} else if (isset($node['value']) and $nodecounters[$node['tag']>1])
{
$tree['children'][++$maxindex]=$node;
}
}
}
if (!$tree['children']) unset($tree['children']);
return $tree;
}