1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

CARP Don't Want It

Discussion in 'Programming' started by clasione, Jun 20, 2005.

  1. #1
    Can anyone tell me why CARP RSS won't use this URL:

    url
     
    clasione, Jun 20, 2005 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Carp don't parse XML per se. It expects an RSS format file of predetermined fields.

    That's off the top of my head.
     
    noppid, Jun 20, 2005 IP
  3. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #3
    That's definitely a custom xml file. It doesn't have the standards you'd see in RSS, Atom, or any other newsfeed - it contains instead a list of properties for each hotel.

    I know that Carp works with amazon xml through a filter, so you could probably do the same kind of thing - make a plugin or a filter or something - or you could just do a custom job yourself.
     
    nevetS, Jun 20, 2005 IP
  4. clasione

    clasione Notable Member

    Messages:
    2,362
    Likes Received:
    158
    Best Answers:
    0
    Trophy Points:
    228
    #4
    I'm probably going to have to pay soeone to do it for me.....

    Anyone want a shot at it, and what's your fee?
     
    clasione, Jun 20, 2005 IP
  5. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #5
    This is not tested, but it should show you the results in an array to work with.

    
    $xmlC = new XmlC();
    $xml_data = file_get_contents( $URL );
    $xmlC->Set_XML_data( $xml_data );
    $results = $xmlC->obj_data->Hotel;
    echo '<pre>';
    print_r($results);
    echo '</pre>';
    
    PHP:
    EDIT: hehe, won't work, that needs a class I used in the past. Sorry. But it would work if you had the class.
     
    noppid, Jun 20, 2005 IP
  6. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #6
    This is partly code from php.net. It returns an array you can work with.

    
    <?php
    $URL = 'http://xml.traveltoday.net/xmlhotel.jsp?xml=%3CHotelRequest%20method=%22runHotelInfoListRequest%22%3E%3CHotelInfoListRequest%3E%3CCity%3ESpringfield%3C/City%3E%3CStateProvince%3EMO%3C/StateProvince%3E%3CCountry%3EUS%3C/Country%3E%3CdataSetRequested%3ECOMPLETE%3C/dataSetRequested%3E%3C/HotelInfoListRequest%3E%3C/HotelRequest%3E';
    
    $curl_handle = curl_init();
    
    // Where should we get the data?
    curl_setopt ($curl_handle, CURLOPT_URL, $URL);
    
    // This says not to dump it directly to the output stream, but instead
    // have it return as a string.
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    
    // the following is optional, but you should consider setting it
    // anyway. It prevents your page from hanging if the remote site is
    // down.
    curl_setopt ($curl_handle, CURLOPT_CONNECTTIMEOUT, 1);
    
    // Now, YOU make the call.
    $file = curl_exec($curl_handle);
    
    // And tell it to shut down (when your done. You can always make more
    // calls if you want.)
    curl_close($curl_handle);
    
    $stack = array();
    
    function startTag($parser, $name, $attrs)
    {
       global $stack;
       $tag=array("name"=>$name,"attrs"=>$attrs); 
       array_push($stack,$tag);
     
    }
    
    function cdata($parser, $cdata)
    {
       global $stack,$i;
      
       if(trim($cdata))
       {   
           $stack[count($stack)-1]['cdata']=$cdata;   
       }
    }
    
    function endTag($parser, $name)
    {
       global $stack; 
       $stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
       array_pop($stack);
    }
    
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startTag", "endTag");
    xml_set_character_data_handler($xml_parser, "cdata");
    
    $data = xml_parse($xml_parser,$file);
    if(!$data) {
       die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    }
    
    xml_parser_free($xml_parser);
    
    print("<pre>\n");
    print_r($stack[0][children]);
    print("</pre>\n");
    
    
    ?>
    
    PHP:
     
    noppid, Jun 20, 2005 IP
  7. clasione

    clasione Notable Member

    Messages:
    2,362
    Likes Received:
    158
    Best Answers:
    0
    Trophy Points:
    228
    #7
    So what should I do with that? Create a php file, stick that in it and then call it with carp?
     
    clasione, Jun 20, 2005 IP
  8. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #8
    Yes, create a php file. No, Don't use carp. That is all ya need to get the xml.

    As you can see after running it, you get an array at the top level "Hotel" in $stack[0][children]. Parse the array to populate your template.
     
    noppid, Jun 20, 2005 IP
  9. clasione

    clasione Notable Member

    Messages:
    2,362
    Likes Received:
    158
    Best Answers:
    0
    Trophy Points:
    228
    #9
    clasione, Jun 21, 2005 IP