SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member Dolby's Avatar
    Join Date
    Jun 2003
    Location
    Wisconsin
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xml parse to variable

    I have the following XML data in a variable coming from a secure curl form

    $xml_data =
    Code:
    <User>
    <flags>A</flags>
    <id>12345</id>
    <name>Dolby</name>
    <premium>Yes</premium>
    </User>
    I need to parse this xml so that each value is in a variable.
    Code:
    $xml['user']['flags'];  //this has the A value in it
    $xml['user']['id'];  //this has the 12345 value in it
    etc...
    I am using php4 on the server and can not yet upgrade to php5 to use simplexml.

    I've been searching for examples but none of the ones I find for xml_parse() show anything close to what I need. Does any one have any suggestions or seen any examples that fit what I need?
    "All I ever wanted was an honest weeks pay
    for an honest days work!"
    - Sgt. Bilko

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Member Dolby's Avatar
    Join Date
    Jun 2003
    Location
    Wisconsin
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've ran across that but dont want to purchase it if its not going to work for me.

    I've been mainly playing and trying to figure how to use something like this...
    Code:
    function startElement($parser, $name, $attrs) {
        global $name;
    }
    
    function endElement($parser, $name) {
        global $insideitem, $tag, $title, $description, $link;
        
    }
    
    function characterData($parser, $data) {
        global $insideitem, $name, $flags, $id, $name;
    
        switch ($name) {
            case "FLAGS":
            $flags .= $data;
            break;
            case "ID":
            $id .= $data;
            break;
            case "NAME":
            $username .= $data;
            break;
            case "PREMIUM":
            $premium .= $data;
            break;
        }
        
    }
    
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    
    while ($data = $xml_data)
        xml_parse($xml_parser, $data, $xml_data)
            or die();
    xml_parser_free($xml_parser);
    
    
    
    echo $username;
    Last edited by Dolby; Mar 6, 2007 at 18:43.
    "All I ever wanted was an honest weeks pay
    for an honest days work!"
    - Sgt. Bilko

  4. #4
    SitePoint Member Dolby's Avatar
    Join Date
    Jun 2003
    Location
    Wisconsin
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I decided to use preg_match_all instead.
    "All I ever wanted was an honest weeks pay
    for an honest days work!"
    - Sgt. Bilko


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •