Java Reference
In-Depth Information
<img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
<b>Current Conditions:</b><br />Mostly Cloudy, 45 F<BR />
<BR /><b>Forecast:</b><BR />Wed - Partly Cloudy. High: 51
Low: 41<br />Thu - Partly Cloudy. High: 57 Low: 40<br
/>Fri - Mostly Cloudy. High: 41 Low: 36<br />Sat - Partly
Cloudy. High: 45 Low: 42<br />Sun - Mostly Cloudy. High:
58 Low: 48<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/
Chicago__IL/*http://weather.yahoo.com/
forecast/USIL0225_f.html">Full Forecast at Yahoo!
Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The
Weather Channel</a>)<br/>
How It Works
In this recipe, you parse an RSS feed and construct an HTML string within the JavaFX
application, and then display the HTML via a
WebView
. The JavaFX application can
retrieve XML information from Yahoo!'s weather service via an URL using a WOEID
(location ID) to target a specific location. Once the XML is parsed, the HTML content
is assembled and rendered onto JavaFX's
WebView
node. The
WebView
object in-
stance is a graph node capable of rendering and retrieving XML or any HTML5 con-
tent. The application will also display a countdown in seconds until the next retrieval
from the weather service.
When accessing weather information for your area through Yahoo!'s weather ser-
vice, you need to obtain a location ID (WOEID) or the URL to the RSS feed associated
with your city. Before I explain the code line by line, consider these steps for obtaining
the RSS feed URL for your local weather forecasts.
1.
2.
Enter a city or ZIP code and press the Go button.
3.
Copy the number located at the trailing end of the URL in the
browser's address bar. That is the location's WOEID.
4.
Insert the WOEID into
http://weather.yahooapis.com/