|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Collections.Generic;
public partial class FetchWeather : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string type = Request.QueryString["type"];
string city = Request.QueryString["city"];
string weatherIcon = "<img src='weathericon.JPG' alt='weather' />";
List<KeyValuePair<string, string>> list2Ret = new List<KeyValuePair<string, string>>();
if ( type == null )
type = "XML";
string xmlPath = Server.MapPath( "." ) + "\\WeatherDetails.xml";
XmlDocument doc = new XmlDocument();
doc.Load( xmlPath );
XmlNodeList nodeList;
if ( type == "XML" )
{
nodeList = doc.SelectNodes( "weatherdetails/weatherreport" );
foreach ( XmlNode node in nodeList )
{
list2Ret.Add( new KeyValuePair<string, string>( node.Attributes["city"].InnerText.ToLower(), node.Attributes["weather"].InnerText ) );
}
for ( int i = 0; i < list2Ret.Count; i++ )
{
if ( list2Ret[i].Key == city.ToLower() )
Response.Write("<br>Weather Report using XML <br> "+ list2Ret[i].Value + "<sup>o</sup> C"+ weatherIcon );
}
}
else if ( type == "JSON" )
{
string toJSON = byLibrary.byComponent.XmlToJSON( doc );
Response.Write( toJSON );
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.