public function XML2PHP($msg)
{
$this->_data = null;
$xp = xml_parser_create();
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
xml_parser_set_option($xp, XML_OPTION_SKIP_WHITE, true);
xml_parser_set_option($xp, XML_OPTION_TARGET_ENCODING, 'ISO-8859-1');
if (!xml_parse_into_struct($xp, $msg, $vals, $index)) {
$error = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($xp)), xml_get_current_line_number($xp));
xml_parser_free($xp);
throw new Exception('oSRS Error - ' . $error);
}
xml_parser_free($xp);
$temp = $depth = array();
foreach ($vals as $value) {
switch ($value['tag']) {
case 'OPS_envelope':
case 'header':
case 'body':
case 'data_block':
break;
case 'version':
case 'msg_id':
case 'msg_type':
$key = '_OPS_' . $value['tag'];
$temp[$key] = $value['value'];
break;
case 'item':
// Not every Item has attributes
if (isset($value['attributes'])) {
$key = $value['attributes']['key'];
} else {
$key = '';
}
switch ($value['type']) {
case 'open':
array_push($depth, $key);
break;
case 'complete':
array_push($depth, $key);
$p = implode('::', $depth);
// enn_change - make sure that $value['value'] is defined
if (isset($value['value'])) {
$temp[$p] = $value['value'];
} else {
$temp[$p] = '';
}
array_pop($depth);
break;
case 'close':
array_pop($depth);
break;
}
break;
case 'dt_assoc':
case 'dt_array':
break;
}
}
foreach ($temp as $key => $value) {
$levels = explode('::', $key);
$num_levels = count($levels);
if ($num_levels == 1) {
$this->_data[$levels[0]] = $value;
} else {
$pointer =& $this->_data;
for ($i = 0; $i < $num_levels; ++$i) {
if (!isset($pointer[$levels[$i]])) {
$pointer[$levels[$i]] = array();
}
$pointer =& $pointer[$levels[$i]];
}
$pointer = $value;
}
}
return $this->_data;
}