Source of file class_XMLParser.php
Size: 3,001 Bytes - Last Modified: 2021-12-23T10:07:55+00:00
/var/www/docs.ssmods.com/process/src/thirdparty/wikiparser-1.0/class_XMLParser.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 | <?php /* * DETAILS * * Provides an XML parser. * * * CREDITS * * Originally by Hans Anderson (http://www.hansanderson.com/php/xml) * Modifications by Carlo Zottman (http://phpjabber.g-blog.net) * Modifications by Steve Blinch (http://www.centova.com) * * * LICENSE * * xmlize() is by Hans Anderson, www.hansanderson.com/contact/ * * Ye Ole "Feel Free To Use it However" License [PHP, BSD, GPL]. * some code in xml_depth is based on code written by other PHPers * as well as one Perl script. Poor programming practice and organization * on my part is to blame for the credit these people aren't receiving. * None of the code was copyrighted, though. * * * REFERENCE * * @ = attributes * # = nested tags * */ class XMLParser { function XMLParser() { } // xmlize() // (c) Hans Anderson / http://www.hansanderson.com/php/xml/ function xmlize($data) { $vals = $index = $array = array(); $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); // XML_OPTION_SKIP_WHITE is disabled as it clobbers valid // newlines in instant messages xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_parse_into_struct($parser, $data, $vals, $index); xml_parser_free($parser); $i = 0; $tagname = $vals[$i]['tag']; $array[$tagname]['@'] = $vals[$i]['attributes']; $array[$tagname]['#'] = $this->_xml_depth($vals, $i); return $array; } // _xml_depth() // (c) Hans Anderson / http://www.hansanderson.com/php/xml/ function _xml_depth($vals, &$i) { $children = array(); if ($vals[$i]['value']) { array_push($children, trim($vals[$i]['value'])); } while (++$i < count($vals)) { switch ($vals[$i]['type']) { case 'cdata': array_push($children, trim($vals[$i]['value'])); break; case 'complete': $tagname = $vals[$i]['tag']; $size = sizeof($children[$tagname]); $children[$tagname][$size]['#'] = trim($vals[$i]['value']); if ($vals[$i]['attributes']) { $children[$tagname][$size]['@'] = $vals[$i]['attributes']; } break; case 'open': $tagname = $vals[$i]['tag']; $size = sizeof($children[$tagname]); if ($vals[$i]['attributes']) { $children[$tagname][$size]['@'] = $vals[$i]['attributes']; $children[$tagname][$size]['#'] = $this->_xml_depth($vals, $i); } else { $children[$tagname][$size]['#'] = $this->_xml_depth($vals, $i); } break; case 'close': return $children; break; } } return $children; } // TraverseXMLize() // (c) acebone@f2s.com, a HUGE help! function TraverseXMLize($array, $arrName = "array", $level = 0) { if ($level == 0) { echo "<pre>"; } while (list($key, $val) = @each($array)) { if (is_array($val)) { $this->TraverseXMLize($val, $arrName . "[" . $key . "]", $level + 1); } else { echo '$' . $arrName . '[' . $key . '] = "' . $val . "\"\n"; } } if ($level == 0) { echo "</pre>"; } } } ?> |