What to use for XML parsing / reading in PHP4

后端 未结 7 864
陌清茗
陌清茗 2020-12-21 16:00

Unfortunatly I have to work in a older web application on a PHP4 server; It now needs to parse a lot of XML for calling webservices (custom p

7条回答
  •  眼角桃花
    2020-12-21 16:44

    I would second Rich Bradshaw's suggestion about the simpleXML backport, but if that's not an option, then xml_parse will do the job in PHP4, and still works after migration to 5.

    $xml = ...; // Get your XML data
    $xml_parser = xml_parser_create();
    
    // _start_element and _end_element are two functions that determine what
    // to do when opening and closing tags are found
    xml_set_element_handler($xml_parser, "_start_element", "_end_element");
    
    // How to handle each char (stripping whitespace if needs be, etc
    xml_set_character_data_handler($xml_parser, "_character_data");  
    
    xml_parse($xml_parser, $xml);
    

    There's a good tutorial here about parsing XML in PHP4 that may be of some use to you.

提交回复
热议问题