Java Reference
In-Depth Information
How to do it...
The shortened code provided next shows how to retrieve and process RSS data using the
Feed API. The omitted portion of the code deals with building the GUI elements, with which
you should already be familiar. You can get the complete listing of the code from ch06/
source-code/src/webservice/YahooWeaherRSS.fx .
// weather data model
class Weather {
public var image:Image;
public var title:String;
public var city:String;
public var region:String;
public var country:String;
public var condition:String;
public var temp:String;
public var windSpeed:String;
public var humidity:String;
public var visibility:String;
public var pressure:String;
public var sunsetTime:String;
public var sunriseTime:String;
}
var zip = "33167";
var weather = Weather{}; // instance to hold weather info
// function to retrieve weather info based on zip code
function loadWeatherInfo (zip:String):Void {
var rss:RssTask = RssTask {
lo cation : "http://weather.yahooapis.com/fo recastrss?p={zip}";
...
//handle Yahoo specific tags
onForeignEvent:function (event:Event){
if( event.type == PullParser.END_ELEMENT and
event.qname.name.equals(" location ")){
weather.city=event.getAttributeValue(
QName{name:"city"});
weather.region=event.getAttributeValue(
QName{name:"region"});
weather.country=event.getAttributeValue(
QName{name:"country"});
}
if( event.type == PullParser.END_ELEMENT and
event.qname.name.equals("condition")){
weather.condition =
event.getAttributeValue("text");
 
Search WWH ::




Custom Search