Click here to Skip to main content
13,253,507 members (67,028 online)
Click here to Skip to main content
Articles » Web Development » Ajax » General » Downloads

Stats

156.6K views
2.3K downloads
123 bookmarked
Posted 26 Nov 2008

Ajax Tutorial for Beginners with XML & JSON: Part 2

, 3 Jan 2009
This article will give you a brief idea about Ajax with XML & JSON
AjaxPart2
App_Data
Bin
byLibrary.dll
byLibrary.dll.refresh
byLibrary.pdb
weathericon.JPG
byLibrary.dll
byLibrary.dll.refresh
byLibrary.pdb
weathericon.JPG
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 3 Jan 2009
Article Copyright 2008 by bhupiyujuan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid