Files
cacti/lib/xml.php
T
Ian Berry 61adb7c463 xml-specific functions
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/trunk/cacti@378 860744bd-22fc-0310-8c96-e9fe5004b5ca
2003-01-13 05:41:41 +00:00

51 lines
1.1 KiB
PHP

<?
function xml2array($data) {
/* mvo voncken@mailandnews.com
original ripped from on the php-manual:gdemartini@bol.com.br
to be used for data retrieval(result-structure is Data oriented) */
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($p, $data, &$vals, &$index);
xml_parser_free($p);
$tree = array();
$i = 0;
$tree = get_children($vals, $i);
return $tree;
}
function get_children($vals, &$i) {
$children = array();
if ($vals[$i]['value']) array_push($children, $vals[$i]['value']);
$prevtag = "";
while (++$i < count($vals)) {
switch ($vals[$i]['type']) {
case 'cdata':
array_push($children, $vals[$i]['value']);
break;
case 'complete':
$children{strtolower($vals[$i]['tag'])} = $vals[$i]['value'];
break;
case 'open':
$j++;
if ($prevtag <> $vals[$i]['tag']) {
$j = 0;
$prevtag = $vals[$i]['tag'];
}
$children{strtolower($vals[$i]['tag'])}[$j] = get_children($vals,$i);
break;
case 'close':
return $children;
}
}
}
?>