RSS Feeds – Reading, Merging & Importing into DataTable

System.Xml.XmlDocument oNewXMLDoc = new XmlDocument();

System.Xml.XmlDocument oDocFirst = new XmlDocument();
oDocFirst.Load("http://www.ameinfo.com/rssfeeds/3593.xml");

XmlNode oNodeWhereInsert1 = oDocFirst.SelectSingleNode("/rss/channel/item");
XmlNode firstTitleNode = oNodeWhereInsert1.ChildNodes.Item(0);
string firstTitle = firstTitleNode.InnerText;

XmlNode firstLinkNode = oNodeWhereInsert1.ChildNodes.Item(1);
string firstLink = firstLinkNode.InnerText;

XmlNode firstDateNode = oNodeWhereInsert1.ChildNodes.Item(3);
string firstDate = firstDateNode.InnerText;

DateTime firstDateTime = DateTime.Parse(firstDate);

Response.Write("Title = " + firstTitle + "
Link = " + firstLink + "
Date = " + firstDateTime.ToString("dd MMMM, yyyy hh:mm"));

///////////// 2nd Data
System.Xml.XmlDocument oDocSecond = new XmlDocument();
oDocSecond.Load("http://campaignme.com/feed/");

XmlNode oNodeWhereInsert2 = oDocSecond.SelectSingleNode("/rss/channel/item");
XmlNode secondTitleNode = oNodeWhereInsert2.ChildNodes.Item(0);
string secondTitle = secondTitleNode.InnerText;

XmlNode secondLinkNode = oNodeWhereInsert2.ChildNodes.Item(1);
string secondLink = secondLinkNode.InnerText;

XmlNode secondDateNode = oNodeWhereInsert2.ChildNodes.Item(3);
string secondDate = secondDateNode.InnerText;

DateTime secondDateTime = DateTime.Parse(secondDate);

Response.Write("

Title = " + secondTitle + "
Link = " + secondLink + "
Date = " + secondDateTime.ToString("dd MMMM, yyyy hh:mm"));

///////////// 3rd Data
System.Xml.XmlDocument oDocThird = new XmlDocument();
oDocThird.Load("http://mediame.com/op_eds_list/feed");

XmlNode oNodeWhereInsert3 = oDocThird.SelectSingleNode("/rss/channel/item");
XmlNode thirdTitleNode = oNodeWhereInsert3.ChildNodes.Item(0);
string thirdTitle = thirdTitleNode.InnerText;

XmlNode thirdLinkNode = oNodeWhereInsert3.ChildNodes.Item(1);
string thirdLink = thirdLinkNode.InnerText;

XmlNode DateNode = oNodeWhereInsert3.SelectSingleNode("/rss/channel/item/pubDate");
string thirdDate = DateNode.InnerText;

DateTime thirdDateTime = DateTime.Parse(thirdDate);

Response.Write("

Title = " + thirdTitle + "
Link = " + thirdLink + "
Date = " + thirdDateTime.ToString("dd MMMM, yyyy hh:mm"));

DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Title", typeof(string));
table.Columns.Add("Link", typeof(string));
table.Columns.Add("Date", typeof(DateTime));

table.Rows.Add(1, firstTitle, firstLink, firstDateTime);
table.Rows.Add(2, secondTitle, secondLink, secondDateTime);
table.Rows.Add(3, thirdTitle, thirdLink, thirdDateTime);

this.GridView2.DataSource = table.DefaultView;
this.GridView2.DataBind();

table.DefaultView.Sort = "Date DESC";

 

this.GridView1.DataSource = table.DefaultView;
this.GridView1.DataBind();
DataSet ds = new DataSet();
StringReader sReader = new StringReader(oDocFirst.InnerXml);
ds.ReadXml(sReader);

Advertisements

~ by UTS on February 28, 2008.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: