note 84758 added to ref.xml

From: Date: Mon, 28 Jul 2008 22:09:24 +0000
Subject: note 84758 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-142875@lists.php.net to get a copy of this message
Finally a simple xml => array class. Functioning like SimpleXML library. <?php class xml { private $parser; private $pointer; public $dom; public function __construct($data) { $this->pointer =& $this->dom; $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($this->parser, "tag_open", "tag_close"); xml_set_character_data_handler($this->parser, "cdata"); xml_parse($this->parser, $data); } private function tag_open($parser, $tag, $attributes) { if (isset($this->pointer[$tag]['@attributes'])) { $content = $this->pointer[$tag]; $this->pointer[$tag] = array(0 => $content); $idx = 1; } else if (isset($this->pointer[$tag])) $idx = count($this->pointer[$tag]); if (isset($idx)) { $this->pointer[$tag][$idx] = Array( '@idx' => $idx, '@parent' => &$this->pointer); $this->pointer =& $this->pointer[$tag][$idx]; } else { $this->pointer[$tag] = Array( '@parent' => &$this->pointer); $this->pointer =& $this->pointer[$tag]; } if (!empty($attributes)) $this->pointer['@attributes'] = $attributes; } private function cdata($parser, $cdata) { $this->pointer['@data'] = $cdata; } private function tag_close($parser, $tag) { $current = & $this->pointer; if (isset($this->pointer['@idx'])) unset($current['@idx']); $this->pointer = & $this->pointer['@parent']; unset($current['@parent']); if (isset($current['@data']) && count($current) == 1) $current = $current['@data']; else if (empty($current['@data'])||$current['@data']==0) unset($current['@data']); } } ?> maybe I'll do some explanations on habr ---- Server IP: 69.147.83.197 Probable Submitter: 91.203.168.97 ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- https://master.php.net/note/edit/84758 Del: integrated -- https://master.php.net/note/delete/84758/integrated Del: useless -- https://master.php.net/note/delete/84758/useless Del: bad code -- https://master.php.net/note/delete/84758/bad+code Del: spam -- https://master.php.net/note/delete/84758/spam Del: non-english -- https://master.php.net/note/delete/84758/non-english Del: in docs -- https://master.php.net/note/delete/84758/in+docs Del: other reasons-- https://master.php.net/note/delete/84758 Reject -- https://master.php.net/note/reject/84758 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142875) next »