note 90621 added to function.xml-parse-into-struct

From: Date: Thu, 30 Apr 2009 19:58:25 +0000
Subject: note 90621 added to function.xml-parse-into-struct
Groups: php.notes 
Request: Send a blank email to php-notes+get-154061@lists.php.net to get a copy of this message
Thanx to jukea i've upgraded the characterData-function to allow the value 0. Here is the new complete code: <?php class XMLParser { var $path; var $result; function cleanString($string) { return trim(str_replace("'", "&#39;", $string)); } function XMLParser($encoding, $data) { $this->path = "\$this->result"; $this->index = 0; $xml_parser = xml_parser_create($encoding); xml_set_object($xml_parser, &$this); xml_set_element_handler($xml_parser, 'startElement', 'endElement'); xml_set_character_data_handler($xml_parser, 'characterData'); xml_parse($xml_parser, $data, true); xml_parser_free($xml_parser); } function startElement($parser, $tag, $attributeList) { $this->path .= "->".$tag; eval("\$data = ".$this->path.";"); if (is_array($data)) { $index = sizeof($data); $this->path .= "[".$index."]"; } else if (is_object($data)) { eval($this->path." = array(".$this->path.");"); $this->path .= "[1]"; } foreach($attributeList as $name => $value) eval($this->path."->".$name. " = '".XMLParser::cleanString($value)."';"); } function endElement($parser, $tag) { $this->path = substr($this->path, 0, strrpos($this->path, "->")); } function characterData($parser, $data) { if (strlen($data = XMLParser::cleanString($data))) eval($this->path." = '$data';"); } } ?> ---- Server IP: 212.63.193.10 Probable Submitter: 81.201.222.52 ---- Manual Page -- http://www.php.net/manual/en/function.xml-parse-into-struct.php Edit -- https://master.php.net/note/edit/90621 Del: integrated -- https://master.php.net/note/delete/90621/integrated Del: useless -- https://master.php.net/note/delete/90621/useless Del: bad code -- https://master.php.net/note/delete/90621/bad+code Del: spam -- https://master.php.net/note/delete/90621/spam Del: non-english -- https://master.php.net/note/delete/90621/non-english Del: in docs -- https://master.php.net/note/delete/90621/in+docs Del: other reasons-- https://master.php.net/note/delete/90621 Reject -- https://master.php.net/note/reject/90621 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154061) next »