protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e) { globalweather.GlobalWeather obj = new globalweather.GlobalWeather(); // WeatherReference.GlobalWeather weatherObject = new WeatherReference.GlobalWeather(); string xmlData = obj.GetWeather(ddlCity.SelectedItem.Text, "india"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlData); XmlNode tempNode = xmlDoc.SelectSingleNode("CurrentWeather/Temperature"); lblWeatherCondition.Text = tempNode.InnerText; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // localhost.CustomerServices wsCustomer = new localhost.CustomerServices(); globalweather.GlobalWeather obj = new globalweather.GlobalWeather(); //string ddl = removeHmtlFromString(obj.GetCitiesByCountry("india")); string ddl = obj.GetCitiesByCountry("india"); //ddl = Regex.Replace(ddl, "<", "<"); //ddl = Regex.Replace(ddl, ">", ">"); // ddl = ddl.Replace("<NewDataSet>", "").Replace("</NewDataSet>", ""); //string filepath = Server.MapPath("XML/city.xml"); //if (!File.Exists(filepath)) //{ // System.IO.FileStream fs = new System.IO.FileStream(filepath, FileMode.Append, FileAccess.Write); // StreamWriter sw = new StreamWriter(fs); // sw.Write(ddl); // sw.Close(); // fs.Close(); //} XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(ddl); //FileStream rfile = new FileStream(filepath, FileMode.Open); //xdoc.Load(rfile); //String address; XmlNodeList list = xdoc.GetElementsByTagName("Table"); DataTable dt = new DataTable("Test"); dt.Columns.Add("city"); dt.Columns.Add("id", typeof(int)); dt.Columns["id"].AutoIncrement = true; dt.Columns["id"].AutoIncrementSeed = 1; // DataTable dtfinal = dt.DefaultView.ToTable(true, new char[] { city, id }); dt.PrimaryKey = new System.Data.DataColumn[] { dt.Columns["id"] }; for (int i = 0; i < list.Count; i++) { XmlElement city = (XmlElement)xdoc.GetElementsByTagName("City")[i]; //ddlCity.DataSource = city.InnerXml.ToString(); //ddlCity.DataBind(); DataRow dr = dt.NewRow(); dr["city"] = city.InnerText.ToString(); dt.Rows.Add(dr); } ddlCity.DataSource = dt; ddlCity.DataTextField = "city"; ddlCity.DataValueField = "id"; ddlCity.DataBind(); ListItem li = new ListItem(); li.Value = "0"; li.Text = "Please Select"; ddlCity.Items.Insert(0, li); //rfile.Close(); //XmlDocument document = new XmlDocument(); //document.Load(strFilePath); //XmlNode node = document.DocumentElement.SelectSingleNode("//City"); //Response.Write("node = " + node); //XmlTextReader reader = new XmlTextReader(ddl); //// Skip non-significant whitespace //reader.WhitespaceHandling = WhitespaceHandling.Significant; //// Read nodes one at a time //while (reader.Read()) //{ // // Print out info on node // Console.WriteLine("{0}: {1}", reader.NodeType.ToString(), reader.Name); //} //string strURL = string.Format("http://www.webservicex.net/globalweather.asmx/GetWeather?CityName={0}&CountryName={1}", "New York", "United States"); //XmlDocument XMLDoc = new XmlDocument(); //XMLDoc.Load(strURL); //string strXML = XMLDoc.ChildNodes[1].ChildNodes[0].InnerText; //XMLDoc = new XmlDocument(); //XMLDoc.LoadXml(strXML); //string strWeatherCondition = XMLDoc.SelectSingleNode("/CurrentWeather/SkyConditions").InnerText; //lblWeatherCondition.Text = strWeatherCondition; //ddlCity.DataSource = ddl; //ddlCity.DataBind(); } }