note 42650 deleted from ref.xml by bjori
| From: | bjori@php.net | Date: | Mon, 09 Oct 2006 11:16:50 +0000 |
| Subject: | note 42650 deleted from ref.xml by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118301@lists.php.net to get a copy of this message | ||
Note Submitter: juliano at setor4 dot com
----
An update of rcotta at ig dot com dot br. The function below will not overwrite an existent element.
<?
function makeXMLTree($file) {
$open_file = fopen($file, "r");
$data = fread($open_file, filesize($file));
$ret = array();
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser);
$hash_stack = array();
$a=0;
foreach ($values as $key => $val) {
switch ($val['type']) {
case 'open':
array_push($hash_stack, $val['tag']);
break;
case 'close':
array_pop($hash_stack);
break;
case 'complete':
array_push($hash_stack, $val['tag']);
// uncomment to see what this function is doing
/* echo("\$ret[$a][" . implode($hash_stack, "][") . "] =
'{$val[value]}';\n");
$a++;*/
eval("
\$ret[\$a][" . implode($hash_stack, "][") . "] =
'{$val[value]}';
\$a++;");
array_pop($hash_stack);
break;
}
}
return $ret;
}
$res = makeXMLTree($xml_file);
print_r($res);
?>