note 59686 deleted from function.xml-parse-into-struct by cmb

From: Date: Sun, 21 Oct 2018 09:29:45 +0000
Subject: note 59686 deleted from function.xml-parse-into-struct by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209475@lists.php.net to get a copy of this message
Note Submitter: p dot gasiorowski at axent dot pl ---- Something similar to kieran's _xml2array, however much more faster. ------ class ObjectFromXML { var $parser; var $iter = 0; var $path = array(); var $xml = array(); function ObjectFromXML($XML) { $this->parser = xml_parser_create(); xml_set_object($this->parser, &$this); xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($this->parser, "hanleTagStart", "hanleTagEnd"); xml_set_character_data_handler($this->parser, "hanleTagCData"); xml_parse($this->parser, $XML); xml_parser_free($this->parser); $this->xml = $this->xml['_children'][0]; } function getEvalPath() { return '$this->xml[' . "'" . implode("']['", $this->path) . "'" . ']'; } function hanleTagStart($parser, $tag, $attributes) { array_push($this->path, '_children'); array_push($this->path, ($this->iter++)); $e = $this->getEvalPath(); eval ($e . "['_name'] = \$tag;"); if ($attributes !== array()) { eval ($e . "['_attributes'] = \$attributes;"); } } function hanleTagCData($parser, $cdata) { $e = $this->getEvalPath(); eval ($e . "['_value'] = \$cdata;"); } function hanleTagEnd($parser, $tag) { array_pop($this->path); array_pop($this->path); } }

« previous php.notes (#209475) next »