note 25781 added to function.xml-parse-into-struct

From: Date: Sat, 05 Oct 2002 20:54:12 +0000
Subject: note 25781 added to function.xml-parse-into-struct
Groups: php.notes 
Request: Send a blank email to php-notes+get-37706@lists.php.net to get a copy of this message
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; } -- http://www.php.net/manual/en/function.xml-parse-into-struct.php http://master.php.net/manage/user-notes.php?action=edit+25781 http://master.php.net/manage/user-notes.php?action=delete+25781 http://master.php.net/manage/user-notes.php?action=reject+25781

« previous php.notes (#37706) next »