ID:               25587
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dan at ghul dot org
-Status:           Open
+Status:           Closed
 Bug Type:         Feature/Change Request
 Operating System: any
 PHP Version:      4.3.3
 New Comment:

simplexml extension, which will be brought into php5, is definitely
what you are looking for.



Previous Comments:
------------------------------------------------------------------------

[2003-09-18 09:20:35] dan at ghul dot org

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("'", "&#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 ($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 this bug report at http://bugs.php.net/?id=25587&edit=1

Reply via email to