note 72051 added to ref.xml

From: Date: Sat, 30 Dec 2006 23:27:20 +0000
Subject: note 72051 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-121120@lists.php.net to get a copy of this message
Time to add my attempt at a very simple script that parses XML into a structure: <?php class Simple_Parser { var $parser; var $error_code; var $error_string; var $current_line; var $current_column; var $data = array(); var $datas = array(); function parse($data) { $this->parser = xml_parser_create('UTF-8'); xml_set_object($this->parser, $this); xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1); xml_set_element_handler($this->parser, 'tag_open', 'tag_close'); xml_set_character_data_handler($this->parser, 'cdata'); if (!xml_parse($this->parser, $data)) { $this->data = array(); $this->error_code = xml_get_error_code($this->parser); $this->error_string = xml_error_string($this->error_code); $this->current_line = xml_get_current_line_number($this->parser); $this->current_column = xml_get_current_column_number($this->parser); } else { $this->data = $this->data['child']; } xml_parser_free($this->parser); } function tag_open($parser, $tag, $attribs) { $this->data['child'][$tag][] = array('data' => '', 'attribs' => $attribs, 'child' => array()); $this->datas[] =& $this->data; $this->data =& $this->data['child'][$tag][count($this->data['child'][$tag])-1]; } function cdata($parser, $cdata) { $this->data['data'] .= $cdata; } function tag_close($parser, $tag) { $this->data =& $this->datas[count($this->datas)-1]; array_pop($this->datas); } } $xml_parser = new Simple_Parser; $xml_parser->parse('<foo><bar>test</bar></foo>'); ?> ---- Server IP: 83.138.144.80 Probable Submitter: 86.139.123.225 ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- https://master.php.net/note/edit/72051 Del: integrated -- https://master.php.net/note/delete/72051/integrated Del: useless -- https://master.php.net/note/delete/72051/useless Del: bad code -- https://master.php.net/note/delete/72051/bad+code Del: spam -- https://master.php.net/note/delete/72051/spam Del: non-english -- https://master.php.net/note/delete/72051/non-english Del: in docs -- https://master.php.net/note/delete/72051/in+docs Del: other reasons-- https://master.php.net/note/delete/72051 Reject -- https://master.php.net/note/reject/72051 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121120) next »