Click Here to Download ProcessRSSorATOMFeed.zip
You can process the content of an Atom 1.0 or RSS 2.0 feed to extract or get details of the feed. .Net framework provide classes to parse the feed data.
We are using System.ServiceModel.Syndication.SyndicationFeedFormatter and System.ServiceModel.Syndication.SyndicationFeed classes.
The SyndicationFeedItem and SyndicationFeed classes gives a generic abstraction of Atom 1.0 and RSS 2.0 feeds and feed items, and provide a common interface to simplify the processing of both feed types. The Rss20FeedFormatter class allows to create a SyndicationFeed object from an RSS 2.0 feed, and the Atom10FeedFormatter class provides support for Atom 1.0 feeds. Both classes are available in the System.ServiceModel.Syndication namespace.
We are using "ReadFrom" method and "Feed" property of these classes.
Here is example for this.
In this example we read the feed and display it's details.
C# Examples :
VB.net Examples :
Output :
This is very useful .Net Tips.
For Beginning .Net articles. Click Here...
Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.
You can process the content of an Atom 1.0 or RSS 2.0 feed to extract or get details of the feed. .Net framework provide classes to parse the feed data.
We are using System.ServiceModel.Syndication.SyndicationFeedFormatter and System.ServiceModel.Syndication.SyndicationFeed classes.
The SyndicationFeedItem and SyndicationFeed classes gives a generic abstraction of Atom 1.0 and RSS 2.0 feeds and feed items, and provide a common interface to simplify the processing of both feed types. The Rss20FeedFormatter class allows to create a SyndicationFeed object from an RSS 2.0 feed, and the Atom10FeedFormatter class provides support for Atom 1.0 feeds. Both classes are available in the System.ServiceModel.Syndication namespace.
We are using "ReadFrom" method and "Feed" property of these classes.
Here is example for this.
In this example we read the feed and display it's details.
C# Examples :
Uri objFeedUrl = null; string strUrl = "http://jayeshsorathia.blogspot.com/rss.xml"; if (strUrl.Length == 0 || String.IsNullOrEmpty(strUrl) || !Uri.TryCreate(strUrl, UriKind.RelativeOrAbsolute, out objFeedUrl)) { Response.Write("Invalid feed."); return; } // Create the web request. WebRequest objReqFeed = WebRequest.Create(objFeedUrl); // Get the data from the feed. WebResponse objResFeed = objReqFeed.GetResponse(); SyndicationFeedFormatter objFeedFormatter = null; XElement feed = XElement.Load(objResFeed.GetResponseStream()); // Check for the feed type if (feed.Name.LocalName == "rss") { objFeedFormatter = new Rss20FeedFormatter(); } else if (feed.Name.LocalName == "feed") { objFeedFormatter = new Atom10FeedFormatter(); } else { Response.Write("Unsupported feed type: " + feed.Name.LocalName); return; } // Read the feed data into the formatter. objFeedFormatter.ReadFrom(feed.CreateReader()); // Display feed Details Response.Write("<b>Feed Title : </b>" + objFeedFormatter.Feed.Title.Text); Response.Write("<br/><br/>"); Response.Write("<b>Feed Description : </b>" + objFeedFormatter.Feed.Description.Text); Response.Write("<br/><br/>"); Response.Write("<b>Items in the Feed : </b>"); Response.Write("<br/><br/>"); foreach (var objItem in objFeedFormatter.Feed.Items) { Response.Write("<b>Title : </b> " + objItem.Title.Text); if (objItem.Summary != null) { Response.Write("<br/><b>Summary : </b>" + objItem.Summary.Text); } Response.Write("<br/><b>Publish Date : </b>" + objItem.PublishDate); Response.Write("<br/><br/>"); }
VB.net Examples :
Dim objFeedUrl As Uri = Nothing Dim strUrl As String = "http://jayeshsorathia.blogspot.com/rss.xml" If strUrl.Length = 0 Or String.IsNullOrEmpty(strUrl) Or Not Uri.TryCreate(strUrl, UriKind.RelativeOrAbsolute, objFeedUrl) Then Response.Write("Invalid feed.") Return End If ' Create the web request. Dim objReqFeed As WebRequest = WebRequest.Create(objFeedUrl) ' Get the data from the feed. Dim objResFeed As WebResponse = objReqFeed.GetResponse() Dim objFeedFormatter As SyndicationFeedFormatter = Nothing Dim feed As XElement = XElement.Load(objResFeed.GetResponseStream()) ' Check for the feed type If feed.Name.LocalName = "rss" Then objFeedFormatter = New Rss20FeedFormatter() ElseIf feed.Name.LocalName = "feed" Then objFeedFormatter = New Atom10FeedFormatter() Else Response.Write("Unsupported feed type: " & feed.Name.LocalName) Return End If ' Read the feed data into the formatter. objFeedFormatter.ReadFrom(feed.CreateReader()) ' Display feed Details Response.Write("<b>Feed Title : </b>" & objFeedFormatter.Feed.Title.Text) Response.Write("<br/><br/>") Response.Write("<b>Feed Description : </b>" & objFeedFormatter.Feed.Description.Text) Response.Write("<br/><br/>") Response.Write("<b>Items in the Feed : </b>") Response.Write("<br/><br/>") Dim objItem As SyndicationItem For Each objItem In objFeedFormatter.Feed.Items Response.Write("<b>Title : </b> " & objItem.Title.Text) If Not objItem.Summary Is Nothing Then Response.Write("<br/><b>Summary : </b>" & objItem.Summary.Text) End If Response.Write("<br/><b>Publish Date : </b>" & objItem.PublishDate.ToString()) Response.Write("<br/><br/>") Next
Output :
![]() |
(To view original image , click on image) |
This is very useful .Net Tips.
For Beginning .Net articles. Click Here...
To learn more regarding XML. Click Here...
Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.