Now that we have all the pieces in place, we need to create
a web page that will display our current weather. The web page contains an XML
control that will be used to display the current weather conditions. Since the
XSL file is static, we add it to the XML control by setting the TransformSource
property.
When the web page loads, it attempts to load the NWS XML
feed as an XML document and then use that XML document to set the XML control's
Document property. If the XML feed is unavailable the default XML file is used to
set the DocumentSource property for XML control instead.
I have created an example weather web page which is shown in
Listing 4. Name the page Weather.aspx and place it in the root directory of
your web application.
Listing 4 - Example of a simple web page that
displays the weather
<%@ Page Language="C#" %>
<%@ OutputCache Location="None" VaryByParam="None" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
try
{
doc.Load("http://www.weather.gov/data/current_obs/KMDW.xml");
Xml1.Document = doc;
}
catch
{
Xml1.DocumentSource = "App_Data/Weather.xml";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Local Weather Conditions</title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family: Arial, 'Microsoft Sans Serif';font-size: 10pt;">
<asp:Xml ID="Xml1"
runat="server" TransformSource="App_Data/Weather.xsl"
EnableViewState="false"></asp:Xml>
</div>
</form>
</body>
</html>