ali raza

C#, .Net , and my thoughts

How to fetch data form Rss

This is some code I used to fetch data from rss links  and insert to database.  Where _RssAgent is containing business logic, having getters, setters and function to insertion in database. you can implement as your requirement 

XmlDocument doc = new XmlDocument();
//Get all Items in the XML file
//Get reference to the first author node in the XML file
XmlNodeList titleList = doc.GetElementsByTagName(“item”);
// loop for all get
for (int _Count = 0; _Count <= titleList.Count – 1; _Count++)
XmlNode authorNode = doc.GetElementsByTagName(“item”)[_Count];
_RssAgent = new clsBlogPost();
foreach (XmlNode child in authorNode.ChildNodes)
if ((child.Name == “title”) && (child.NodeType == XmlNodeType.Element))

// Assign Title of post to some variable
_RssAgent.PostTitle = child.FirstChild.Value;
if ((child.Name == “description”) && (child.NodeType == XmlNodeType.Element))

// assign the description of rss item to variable
_RssAgent.Content = child.FirstChild.Value;
if ((child.Name == “link”) && (child.NodeType == XmlNodeType.Element))
_RssAgent.PostUrl = child.FirstChild.Value;
if ((child.Name == “pubDate”) && (child.NodeType == XmlNodeType.Element))

//if pub date found then assign it to date
_RssAgent.PostedDate = Convert.ToDateTime(child.FirstChild.Value);
if (_RssAgent.PostedDate == Convert.ToDateTime(“1/1/0001”))
_RssAgent.PostedDate = Convert.ToDateTime(“1/1/1900”);
_RssAgent.DateIndexed = DateTime.Now;
_RssAgent.BlogId = _RssId;

///insertion method call you can use ur own code here

Leave a Reply

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

You are commenting using your 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: