…and, as usual, the guys at the National Oceanic & Atmospheric Administration have their eye on what’s going on. They provide several feeds detailing the hurricane situation. You can find them here.
I’ve written a little web page that makes use of the feed, just to show you how to consume it. The code’s below and is fairly self explanatory.
protected void Page_Load(object sender, EventArgs e)
{
//GS - Remove any content already written to the buffer
Response.Clear();
//GS - Write the html header
Response.ContentType = "text/html";
//GS - Open the RSS feed
XPathDocument xpd = null;
try
{
xpd =
new XPathDocument(@"http://www.nhc.noaa.gov/index-at.xml");
}
catch (XmlException xe)
{
Response.Write("The following xml error occurred: " + xe.Message);
Response.End();
}
//GS - Create a navigator
XPathNavigator xpn = xpd.CreateNavigator();
//GS - Get the URL to the logo of NOAA
try
{
XPathNavigator Node =
xpn.SelectSingleNode(@"/rss/channel/image/url");
//GS - Write the image
Response.Write("<img src='" + Node.InnerXml + "' /><p />");
//GS - Get the title
Node = xpn.SelectSingleNode(@"/rss/channel/title");
//GS - Write the out the title
Response.Write("<h1>" + Node.InnerXml + "</h1>");
//GS - Get the subtitle
Node = xpn.SelectSingleNode(@"/rss/channel/description");
//GS - Write out the subtitle
Response.Write("<h2>" + Node.InnerXml + "</h2>");
//GS - Get all the items
XPathNodeIterator xpni = xpn.Select(@"/rss/channel/item");
//GS - Start an unordered list
Response.Write("<ul>");
//GS - Add each item to the list
string title = "";
string url = "";
while (xpni.MoveNext())
{
if (xpni.Current.MoveToFirstChild())
{
title = xpni.Current.InnerXml;
if (xpni.Current.MoveToNext())
{
url = xpni.Current.InnerXml;
}
}
Response.Write("<li><a href='" + url + "'>" +
title + "</a></li>");
}
//GS - Close the unordered list
Response.Write("</ul>");
//GS - We're done. Flush and close the buffer.
Response.End();
}
catch (XPathException xpe)
{
Response.Write("The following XPathException occurred: " +
xpe.Message);
Response.End();
}
}
Tags: Hurricanes, RSS, C#