function) * @var array() */ var $taghandler = array(); /** * Current CDATA value * @var string */ var $cdata = ''; /** * Tag stack of all open nodes * @var array */ var $stack = array(); /** * Node list for all open tag attributes * @var array */ var $attribs = array(); /** * Resulting parsed array * @var array */ var $result = array(); /** * Constructor */ function XML_Parser($registry) { $this->registry = $registry; } /** * Parse an XML file * * @param string XML file data * * @return array Array with all the XML data parsed */ function parse($data) { $this->stack = array(); $this->attribs = array(); $this->result = array(); $this->cdata = ''; // create a new parser $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($this->parser, 'handle_tag_start', 'handle_tag_end'); xml_set_character_data_handler($this->parser, 'handle_cdata'); $this->attach_node($this->result); // parse the data and check for errors if (!xml_parse($this->parser, $data)) { $error['code'] = xml_get_error_code($this->parser); $error['string'] = xml_error_string($error['code']); $error['line'] = xml_get_current_line_number($this->parser); $error['column'] = xml_get_current_column_number($this->parser); trigger_error("XML Error: $error[string] at line $error[line] colunn $error[column]", E_USER_ERROR); exit; } // destroy the parser xml_parser_free($this->parser); // done... send the results back return $this->result; } /** * Process the opening location of an XML tag * * @param integer XML parser * @param string Tag name * @param array Tag attributes */ function handle_tag_start(&$parser, $name, $attrs) { // trim attributes array_walk($attrs, 'trim'); // existing node set if (isset($this->attribs["$name"])) { // node set has < 1 child nodes if (!isset($this->attribs["$name"][0])) { $tmp = $this->attribs["$name"]; unset($this->attribs["$name"]); $this->attribs["$name"][0] = $tmp; } // create a new child node $this->attach_node($this->attribs["$name"][] = (array)$attrs); } // node set doesn't exist, so create it else { $this->attach_node($this->attribs["$name"] = (array)$attrs); } } /** * Process XML CDATA * * @param integer XML parser * @param string CDATA from tag */ function handle_cdata(&$parser, $data) { $this->cdata .= $data; } /** * Process the closing of an XML tag * * @param integer XML parser * @param string Tag name */ function handle_tag_end(&$parser, $name) { global $_isso; // attach data to the node if (($this->cdata = trim($this->cdata)) != '') { // if we have a data handler, operate it now if (isset($this->taghandler["$name"])) { $_isso->debug("handler: " . $this->taghandler["$name"]); if (function_exists($this->taghandler["$name"])) { $this->cdata = $this->taghandler["$name"]($this->cdata, $this); } else { trigger_error('Could not find the function [' . $this->taghandler["$name"] . '()] for the XML tag "' . $name . '"', E_USER_ERROR); } } $this->attribs['value'] = $this->cdata; } $this->cdata = ''; // remove the node $this->detach_node(); } /** * Shifts the node tree * * @param array Node to place into the stack */ function attach_node(&$node) { // create a new node $this->stack[ count($this->stack) ] =& $node; // new attributes to work with $this->attribs =& $node; } /** * Unshifts the node tree */ function detach_node() { // drop the newest node unset($this->stack[ count($this->stack) - 1 ]); // assign the attributes to the next newest node $this->attribs =& $this->stack[ count($this->stack) - 1 ]; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>