I have finally taken the jump from VB.net to C# so I'm still having some issues. I am making a simple weather app that connects through a RSS feed. I want it to return a label that determines if it is freezing outside, however; I am having issues converting the temperature string to an integer so I can determine if the temperature is less than or equal to 32 degrees. Any ideas?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace WeatherApp
{
public partial class frmWeather : Form
{
string Temperature;
public frmWeather()
{
InitializeComponent();
}
private void getWeather()
{
string query = string.Format("http://weather.yahooapis.com/forecastrss?w=" + txtZip.Text);
XmlDocument wData = new XmlDocument();
wData.Load(query);
XmlNamespaceManager manager = new XmlNamespaceManager(wData.NameTable);
manager.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
XmlNode channel = wData.SelectSingleNode("rss").SelectSingleNode("channel");
XmlNodeList nodes = wData.SelectNodes("/rss/channel/item/yweather:forecast", manager);
Temperature = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["temp"].Value;
}
private void tmrWeather_Tick(object sender, EventArgs e)
{
getWeather();
DateTime now = DateTime.Now;
lblTemp.Text = "" + Temperature;
if (lblTemp.Text <= "32")
{
lblResult.Text = "It is freezing outside!";
}
}
}
}