'; $result = xmlToArray($vals, count($vals)); print_r($result); echo ''; // Turns XML files in to a multi-level array. function xmlToArray ($xml, $limit = false, $start = 0) { static $counter = 0; global $sizeofXML; $counter = !empty($counter) ? $counter : $start; $this_level = 0; $array = array(); $count = $limit === false ? $sizeofXML : $limit - $start; $i = $counter; for (; $i < $count; $i++) {//echo $counter, "\n"; $counter++; // Reference to make future code cleaner. $element = &$xml[$i]; // Skip cdata. It doesn't do anything for us here. if ($element['type'] == 'cdata') continue; // End the node. (I know it seems backwards to end it before starting it. Otherwise you get an extra row in there) if ($element['type'] == 'close') {//echo $i; print_r($element);echo $counter, ' ', $this_level, "\n"; //$counter += $this_level; return $array; } // Set up the node. if (!isset($array[$this_level])) $array[$this_level] = array('tag' => $element['tag']); $tag = &$array[$this_level]; // DEBUGGING! $tag['xml_array_num'] = $i; $tag['xml_array_limit'] = $count - $i; // Add the attributes. if (isset($element['attributes'])) $tag['attributes'] = $element['attributes']; // Maybe this element has a value? Lets add it. if (!empty($element['value'])) $tag['value'] = VALUE_LIMIT > 0 ? substr($element['value'], 0, VALUE_LIMIT) : $element['value']; // Let's open it up for children (child nodes)... recursive. if ($element['type'] == 'open') { $counter++; $tag['children'] = xmlToArray($xml, $count - $i); } // A counter to track the array. $this_level++; //$counter++; } return $array; } ?>