Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Mashup question

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1671 Views
  • freeyland
    Avatar
    Community Member
    22 Posts

    Mashup question Link to this post

    I want to integrate the weather from yahoo into my site.
    http://xml.weather.yahoo.com/forecastrss?u=C&p=AUXX0118

    The problem is that <yweather:condition text="Partly Cloudy" code="30" temp="15" date="Thu, 09 Aug 2007 10:55 am CEST" /> is not imported because of the ':'

    Does someone know how to read element with column in SimpleXMLElement?

    Is there a way to cash the output?

  • laktek
    Avatar
    Google Summer of Code Hacker
    76 Posts

    Re: Mashup question Link to this post

    Freeyland, if you want to read namespaced elements (qname) best practice would be to use Xpath. You could try out some query such as ;

    $conditions = $xml->xpath("//yweather:condition");

    But to make the whole process easy I've made an update to the mashups module which could handle such feeds. You can download the latest build in the trunk of mashups module and try out the following code. This will fetch the attribute values of condition tag in Yahoo Weather feed.

    In your controller;

    function YahooWeather(){
          $yw = new RestfulService("http://weather.yahooapis.com/forecastrss");
          $params = array(
                "u" => "c",
                "p" => "USIL0225"
             );
          $yw->setQueryString($params);
          $conn = $yw->connect();
          $result = $yw->searchAttributes($conn, "//yweather:condition");
          
          return $result;
       }

    and in the template;
    [html]
    <% control YahooWeather %>
       <p>weather conditions for $date<br/>
        $text - tempreature -$temp</p>
    <% end_control %>
    [/html]

    Hope this helps

    >>Is there a way to cash the output?
    Currently Mashups module doesn't support caching, but it's something on the road maps for future releases.

  • freeyland
    Avatar
    Community Member
    22 Posts

    Re: Mashup question Link to this post

    Thanx!

    1671 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.