curr_tag * @description: a string representation of the current tag. It is ALWAYS in upper case * * @var: $this->repeat * @description: look below * **************************************************** *@extra-info: the php xml parser handler specail chars that are encoded with entites as a seperate data cell. *We get around this by using a counter to determine if the xml parser is looking at the same cell. This parser automatically *Keeps track of this with the $this->repeat var. $this->repeat == true when the cell is repeated, false when it isn't. **/ var $xml_data = 0; //the xml data var $tag_pos = -1; //intertal tagPos counters var $curr_tag; //defines the current tag that the parser is parsing var $ent_c = 0; //the current entitie counter var $prev_ent_c = 0; //the previous entity counter var $repeat; //a boolean determining if the parser is looking at the same Node (which means it is parsering entities) function xmlParser() { $this->parser = xml_parser_create(); } function _openFile($file) { $this->_parsePrepare(); //sets all the xml parsing vars if($this->xml_data = file_get_contents($file)) { return true; } else { exit('Error reading file'); } } function _parsePrepare() { $this->stack = array(); // this keeps track of what tag level you're at xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "_startElementHandler", "_endElementHandler"); xml_set_character_data_handler($this->parser, "_dataHandler"); } /** *@param: $file, defines the URL tot he file to be parsed *@description: parsers the XML from the file specifies **/ function parseXML($file) { $this->_openFile($file); xml_parse($this->parser, $this->xml_data); $this->doneParse(); $this->free(); } function _startElementHandler($parser, $name, $attribs) { $this->ent_c++; //entities fix $this->tag_pos++; //increases the tag position counter $this->stack[] = $name; $this->curr_tag = $this->stack[$this->tag_pos]; $this->startElementHandler($name, $attribs); } function _endElementHandler($parser, $name) { $this->ent_c++; //entites fix $this->tag_pos-=1; array_pop($this->stack); if($this->tag_pos!=-1) {//keeps track of what the current tag is $this->curr_tag = $this->stack[$this->tag_pos]; } else {$curr_tag=0;} $this->endElementHandler($name); } function _dataHandler($parser, $data) {//handles the character data if($this->prev_ent_c == $this->ent_c) {//if the parser is looking at the same cell $this->repeat = true; //then it is a repeat } else {//if not then it is not a repeat $this->repeat = false; } $this->prev_ent_c = $this->ent_c; $this->dataHandler($data); //send the data off to the parent function } function free() { xml_parser_free($this->parser); } } ?>