دوست عزیز
من این تابع رو نوشتم :
publicvoid ProcessRSSItemIR(string rssURL)
{
try
{
StringBuilder strBuilder = newStringBuilder();
System.Net.WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream rssStream = myResponse.GetResponseStream();
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();
rssDoc.Load(rssStream);
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("root/row");
string title = "";
string link = "";
string description24 = "";
string description72 = "";
for (int i = 0; i < rssItems.Count; i++)
{
System.Xml.XmlNode rssDetail;
rssDetail = rssItems.Item(i).SelectSingleNode("fcity");
if (rssDetail != null)
{
title = rssDetail.InnerText;
}
else
{
title = "";
}
//rssDetail = rssItems.Item(i).SelectSingleNode("Airstate24_1");
//if (rssDetail != null)
//{
// link = rssDetail.InnerText;
//}
//else
//{
// link = "";
//}
rssDetail = rssItems.Item(i).SelectSingleNode("Airstate24_1");
if (rssDetail != null)
{
description24 = rssDetail.InnerText;
}
else
{
description24 = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("Airstate24_2");
if (rssDetail != null)
{
description24 = description24 + " , " + rssDetail.InnerText;
}
else
{
description24 = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("Airstate24_1");
if (rssDetail != null)
{
description72 = rssDetail.InnerText;
}
else
{
description72 = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("Airstate24_2");
if (rssDetail != null)
{
description72 = description72 + " , " + rssDetail.InnerText;
}
else
{
description72 = "";
}
strBuilder.Append("<table > ");
// Response.Write("<p><b><a href='" + link + "' target='new'>" + title + "</a></b><br/>");
strBuilder.Append("<tr ><td ><br><h4 > <p class=lblTitleRSS>" + title + "</p></h4></td></tr>");
strBuilder.Append("<tr><td ><p class=lblTitle> 24 ساعت آینده</p></td></tr>");
strBuilder.Append("<tr><td> <p class=lblDescriptionRSS>" + description24 + "</p></td></tr>");
strBuilder.Append("<tr><td ><p class=lblTitle>72 ساعت آینده</p></td></tr>");
strBuilder.Append("<tr><td> <p class=lblDescriptionRSS>" + description24 + "</p></td></tr>");
strBuilder.Append("</table>");
//Response.Write(description + "</p>");
lblWeather.Text = strBuilder.ToString();
}
}
catch { }
}
نحوه فراخوانی :
string rssURL = "http://www.weather.ir/farsi/RSS/xml-forecast.asp";
ProcessRSSItemIR(rssURL);