cur_line ++; if($this->cur_line = '1'){ echo "
"; $indent = '    '; } echo "<$name>"; if (count($attribs)) { foreach ($attribs as $k => $v) { echo " $k=\"$v\""; } } } public function FoundTagData($parser,$data){ echo " $data "; } public function FoundEndTag($parser,$name){ echo "</$name>"; $this->cur_line--; $num ++; } public function parse($file,$encode = 'UTF-8'){ if(!$this->xml_f = @fopen($file,"r")){ die('Error opening '.$file); } $this->xml_parser = xml_parser_create($encode); //Set some infomationz xml_set_object($this->xml_parser,$this); xml_set_element_handler($this->xml_parser,'FoundStartTag','FoundEndTag'); xml_set_character_data_handler($this->xml_parser,'FoundTagData'); $size = filesize($file); while ($data = fread($this->xml_f, 4096)) { xml_parse($this->xml_parser, $data, feof($this->xml_f)); } //clears out the current XML parser xml_parser_free($this->xml_parser); } } $xml = new mccms_xmlParser; $xml->parse('xml.xml'); ?>