I have this script I grabbed off this board I believe, (shown below) that parses xml beautifully (or so i thought)... It doesn't throw any errors, but it doesn't seem to grab all the children of some elements.... any ideas? I use the same function on a similar feed from the same vendor... and it works fine. I'm bamboozuled???
//Take XML and make array
function xmlize($URL, $WHITE=1) {
//load_xml simply loads the xml file into a string
$data = load_xml($URL);
$data = trim($data);
$vals = $index = $array = array();
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
if ( !xml_parse_into_struct($parser, $data, $vals, $index) ) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
$i = 0;
$tagname = $vals[$i]['tag'];
if ( isset ($vals[$i]['attributes'] ) ) {
$array[$tagname]['@'] = $vals[$i]['attributes'];
} else {
$array[$tagname]['@'] = array();
}
$array[$tagname]["#"] = xml_depth($vals, $i);
return $array;
}
//function used with xmlize()
function xml_depth($vals, &$i) {
$children = array();
if (isset($vals[$i]['value'])) {
array_push($children, $vals[$i]['value']);
}
while (++$i < count($vals)) {
switch ($vals[$i]['type']) {
case 'open':
if ( isset ( $vals[$i]['tag'] ) ) {
$tagname = $vals[$i]['tag'];
} else {
$tagname = '';
}
if ( isset ( $children[$tagname] ) ) {
$size = sizeof($children[$tagname]);
} else {
$size = 0;
}
if ( isset ( $vals[$i]['attributes'] ) ) {
$children[$tagname][$size]['@'] = $vals[$i]["attributes"];
}
$children[$tagname][$size]['#'] = xml_depth($vals, $i);
break;
case 'cdata':
array_push($children, $vals[$i]['value']);
break;
case 'complete':
$tagname = $vals[$i]['tag'];
if( isset ($children[$tagname]) ) {
$size = sizeof($children[$tagname]);
} else {
$size = 0;
}
if( isset ( $vals[$i]['value'] ) ) {
$children[$tagname][$size]["#"] = $vals[$i]['value'];
} else {
$children[$tagname][$size]["#"] = '';
}
if ( isset ($vals[$i]['attributes']) ) {
$children[$tagname][$size]['@'] = $vals[$i]['attributes'];
}
break;
case 'close':
return $children;
break;
}
}
return $children;
}