Files
cacti/lib/xml.php
T
Ian Berry 15a54df00a '<?' -> '<?php', updated copyright on top of each file
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/trunk/cacti@446 860744bd-22fc-0310-8c96-e9fe5004b5ca
2003-01-29 02:40:41 +00:00

75 lines
2.8 KiB
PHP

<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2003 Ian Berry |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| cacti: a php-based graphing solution |
+-------------------------------------------------------------------------+
| Most of this code has been designed, written and is maintained by |
| Ian Berry. See about.php for specific developer credit. Any questions |
| or comments regarding this code should be directed to: |
| - iberry@raxnet.net |
+-------------------------------------------------------------------------+
| - raXnet - http://www.raxnet.net/ |
+-------------------------------------------------------------------------+
*/
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;
}
}
}
?>