Click here to Skip to main content
12,455,517 members (61,616 online)
Click here to Skip to main content
Articles » Web Development » Ajax » General » Downloads

Stats

145.4K views
2.2K downloads
122 bookmarked
Posted

Ajax Tutorial for Beginners with XML & JSON: Part 2

, 3 Jan 2009 CPOL
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...

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