|
using System;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Xml.XPath;
using System.Text;
using System.Net;
using System.IO;
public partial class CricinfoAspNet : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCricinfo_Click(object sender, EventArgs e)
{
Response.Clear();
// create here table and columns that will be used
// for storing items from the xml file for later binding into grid
DataTable dtable = new DataTable();
dtable.Columns.Add(new DataColumn("Match Name"));
dtable.Columns.Add(new DataColumn("View Match"));
// fetch webrequest. Here, give the path of the location where rss feed is stored.
WebRequest WebReq = WebRequest.Create("http://static.cricinfo.com/rss/livescores.xml");
//get webresponse from the webrequset
WebResponse webRes = WebReq.GetResponse();
//use stream to stremline the input from from webresponse.
Stream rssStream = webRes.GetResponseStream();
// Create new xml document and load a XML Document
// with the strem.
XmlDocument xmlDoc = new XmlDocument();
//loads the url from the stream
xmlDoc.Load(rssStream);
// use XmlNodeList to get the matching xmlnodes from the xmldocument
XmlNodeList xmlNodeList = xmlDoc.SelectNodes("rss/channel/item");
//create array of the object for creating the row
object[] RowValues = { "", "" };
//Make a Loop through RSS Feed items
for (int i = 0; i < xmlNodeList.Count; i++)
{
XmlNode xmlNode;
xmlNode = xmlNodeList.Item(i).SelectSingleNode("title");
if (xmlNode != null)
{
RowValues[0] = xmlNode.InnerText;
}
else
{
RowValues[0] = "";
}
xmlNode = xmlNodeList.Item(i).SelectSingleNode("guid");
if (xmlNode != null)
{
RowValues[1] = xmlNode.InnerText;
}
else
{
RowValues[1] = "";
}
// creating datarow and add it to the datatable
DataRow dRow;
dRow = dtable.Rows.Add(RowValues);
dtable.AcceptChanges();
}
// finally bind the grid....
grvRSS.DataSource = dtable;
grvRSS.DataBind();
}
}
|
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.
Am Indrajeet T. Sutar. I am a web developer. I am working on .net technology. I have completed my Masters in Computers and Management (people call it as MCA, MBA etc.) Apart from programming i do photography (not regularly though), traveling and reading books.