Display Local Weather Data On Your Site
page 6 of 7
by Andrew Mooney
Average Rating: 
Views (Total / Last 10 Days): 42510/ 77

Putting the Weather on a Web Page

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"
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            Xml1.Document = doc;
            Xml1.DocumentSource = "App_Data/Weather.xml";
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Local Weather Conditions</title>
<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"

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-28 7:50:36 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search