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 Weather; // RssFeedData.cs
using System.Net; // HttpWebRequest
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public string PubDate;
public List<RssFeedData> ReadFeed(string url)
{
List<RssFeedData> rssFeedItems = new List<RssFeedData>();
HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(url);
using (DataSet rssData = new DataSet())
{
rssData.ReadXml(rssFeed.GetResponse().GetResponseStream());
foreach (DataRow row in rssData.Tables[“channel”].Rows)
{
PubDate = Convert.ToString(row[“pubDate”]);
System.Diagnostics.Trace.WriteLine(PubDate);
}
foreach (DataRow row in rssData.Tables[“data”].Rows)
{
rssFeedItems.Add(new RssFeedData
{
Hour = Convert.ToInt32(row[“hour”]),
Day = Convert.ToInt32(row[“day”]),
Temperature = Convert.ToDouble(row[“temp”]),
MaximumTemperature = Convert.ToDouble(row[“tmx”]),
LowTemperature = Convert.ToDouble(row[“tmn”]),
Sky = Convert.ToInt32(row[“sky”]),
Pty = Convert.ToInt32(row[“pty”]),
WeatherForecast = Convert.ToString(row[“wfKor”]),
Pop = Convert.ToInt32(row[“pop”]),
Rain = Convert.ToDouble(row[“r12”]),
Snow = Convert.ToDouble(row[“s12”]),
Wind = Convert.ToDouble(row[“ws”]),
WindDirection = Convert.ToString(row[“wdKor”]),
Humidity = Convert.ToInt32(row[“reh”])
});
}
}
return rssFeedItems;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// 종로구 가회동
List<RssFeedData> aList = ReadFeed(“http://www.kma.go.kr/wid/queryDFSRSS.jsp?zone=1111060000“);
foreach (var item in aList)
System.Diagnostics.Trace.WriteLine(item);
label1.Text = PubDate;
dataGridView1.DataSource = aList;
}
}
}