X

An Oracle blog about BI Publisher

  • July 24, 2006

Phew ... what a scorcher ...

Having been here nearly 7 years Im sure it has been as hot as it was this weekend but I guess you forget how hot it was last summer. Still, its great to be here having to gripe about how hot it is and to have friends that have a pool. Back in the UK, we would be complaining about the rain ... maybe not this past week thou and as for a pool ... I guess it could double as an ice rink in the winter. 



To keep in with the weather theme, I thought I would cover how to get an external data source into your output, RSS feeds are now pervasive across the web, providing news, weather, travel and jokes, you can even get one for this blog. Of course you may have a web service that can serve up XML that can be incorporated into your reports.
I'm going to deal with an RSS weather feed from Yahoo!, they have a very nice, customizable feed that accepts a zip code for those in the USA and for the est of the world (an the US) they have a location id, more details here.
For Oracle HQ we have the following URL passing the zip code for our area:

http://xml.weather.yahoo.com/forecastrss?p=94065

For my home town in the UK:



http://xml.weather.yahoo.com/forecastrss?p=UKXX0899










Current Conditions:
Sunny, 110 F

Forecast:
Mon - Mostly Clear. High: 97 Low: 64
Tue - Mostly Sunny. High: 92 Low: 60

Full Forecast at Yahoo! Weather
(provided by The Weather Channel)


This generates standard RSS formatted XML thus:



<rss version="2.0">
  <channel>
  <title>Yahoo! Weather - Redwood City, CA</title>
   <description>Yahoo! Weather for Redwood City, CA</description>
   <language>en-us</language>
   <lastBuildDate>Mon, 24 Jul 2006 12:47 pm PDT</lastBuildDate>
   <ttl>60</ttl>
   <yweather:location city="Redwood City" region="CA" country="US"/>
   <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
   <yweather:wind chill="88" direction="340" speed="12"/>
   <yweather:atmosphere humidity="29" visibility="32000" pressure="29.72" rising="2"/>
   <yweather:astronomy sunrise="6:07 am" sunset="8:24 pm"/>
   ...
We can incorporate this content into our template quite simply. If you have XML Publisher enterprise you have a couple of options:




  1. Create a URL based data source, this can be combined with other sources by the extraction engine to generate a combined data set. You can then reference the weather data directly in your template.


  2. For those of you using Oracle Applications or an XMLP API you can use a native XSL function to pull the document in at runtime. Its called simply document(). It takes a URI as an argument and you can easily load the document into a variable thus:



    <?variable:YWeather;document("http://xml.weather.yahoo.com/forecastrss?p=94065")?>



    We can then reference our variable which is actually holding the complete RSS document and build whatever layout we wish against it.



So there are a couple of things we need to be wary of when navigating this RSS XML in our template.


  1. We need to declare the variable before we write any fields against it. If we dont we're going to get an error.


  2. We then need to create a loop over the document: <?for-each:$YWeather/*?>

  3. If you take a look at the XML you'll notice many of the elements have a 'yweather:' prefix. This is a namesace that needs to be declared in our template too so that the engine understands the elements at runtime. Its a simple declaration:
     <?namespace:yweather=http://xml.weather.yahoo.com/ns/rss/1.0?> - the URL is taken from the XML.
    Once the namespace is declared we can reference the elements safely e.g. <?yweather:location/@city?> - you may have noticed the XML makes the use of attributes for the data. We reference those using the "@" character.

  4. Lastly, the data references an image to give the user an idea of the weather, sunny, partially cloudy (I prefer the term mostly sunny, cos my glass is always half full :o), etc. Now I had to do some funky stuff to reference the image. The RSS XML does not have a clear URL to the image in an element. Its there in the 'description' element embedded inside some HTML but I did not want to parse that out for now, we'll save that for another time. So I'm still using a dummy image and then constructing a URL using the concat command but the XMLP parser gets upset when it sees the namespace, we end up with something like:
        url:{concat('http://us.i1.yimg.com/us.yimg.com/i/us/we/52/',yweather:forecast[1]/@code,'.gif')}
    which does not get resolved correctly. So I created a variable 'WImg' to hold the image number:
        <?variable@incontext:WImg yweather:forecast[1]/@code?>
    you need the @incontext to get the variable declaration in the correct place. We can then use the concat function to build the image URL:
         url:{concat('http://us.i1.yimg.com/us.yimg.com/i/us/we/52/',$WImg,'.gif')}

Once we have all this the rest of the template is straightforward stuff. You can find a sample here. Dont forget if you are running behind a firewall you need to set your java prefs so that XMLP can get outside and retrieve this stuff.



Now for a quick dip in that pool and something icy to drink ...



 

Join the discussion

Comments ( 4 )
  • Lance Slimmer Friday, May 21, 2010
    I don't get it. Does this apply in anyway to long term insurance?
  • Credit Suisse Gold Bars Sunday, August 15, 2010
    What an outstanding job you have done. You have served many people by creating this post. Hats off to you. Thank you and looking more like these posts.
  • Andrea Duka Saturday, September 11, 2010
    OIL THAT,S BEEN IN THE WATER FOR MONTHS JUST DOSE NOT GO A WAY .. THE SKIMMERS COULD NOT KEEP UP WITH THE OIL....
  • Drew Bazin Saturday, October 9, 2010
    For you to feel so firmly about this I really think you got your idea across with this piece of writing.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.