From: dan at ghul dot org Operating system: any PHP version: 4.3.3 PHP Bug Type: Feature/Change Request Bug description: xml_parse_into_struct
Description: ------------ this is a feature request: please consider adding/replacing the useless xlm_parse_into_struct by something more useful that returns a struct at least close to the DOM! as you can see from posts all around, noone can really cope with the result of this parser and almost everyone goes ahead and builds his own parser to get a reasonable data struct. that's a waste of time. there are plenty of solutions around that describe what people expect from a _parse_into_struct function. take Adam Tylmad's code for example. the result is squieky clean!! what about taking that and implementing it? you'd make lotsa people happy... if you need xml_parse_into_struct for backwards compatibility, insert a new function that provides proper functionality.or then to quote a post from the manpage: ------ There are alot of reasons to make this functionality at least deprecated and replace it with a real XML parser. ------ Reproduce code: --------------- <?php class XMLParser { var $path; var $result; function cleanString($string) { return trim(str_replace("'", "'", $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 ($data = XMLParser::cleanString($data)) eval($this->path." = '$data';"); } } ?> Expected result: ---------------- gdemartini's xml-example generates this structure: stdClass Object ( [FORM] => stdClass Object ( [SECTION] => stdClass Object ( [NAME] => Data [EDITFIELD] => stdClass Object ( [LABEL] => Text: [NAME] => poll_text [LENGTH] => 255 [SIZE] => 56 [REQUIRED] => T ) [MEMOFIELD] => stdClass Object ( [LABEL] => Options [NAME] => options [COLS] => 56 [ROWS] => 5 [REQUIRED] => T ) ) ) ) the moldb example generates this structure: stdClass Object ( [MOLDB] => stdClass Object ( [MOLECULE] => Array ( [0] => stdClass Object ( [NAME] => Alanine [SYMBOL] => ala [CODE] => A [TYPE] => hydrophobic ) [1] => stdClass Object ( [NAME] => Lysine [SYMBOL] => lys [CODE] => K [TYPE] => charged ) ) ) ) -- Edit bug report at http://bugs.php.net/?id=25587&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25587&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25587&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=25587&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=25587&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=25587&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=25587&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=25587&r=support Expected behavior: http://bugs.php.net/fix.php?id=25587&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=25587&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=25587&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=25587&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25587&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=25587&r=dst IIS Stability: http://bugs.php.net/fix.php?id=25587&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=25587&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=25587&r=float