Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to consume an RSS feed

Tags:

c#

asp.net

rss

I'm currently working on an ASP.NET Website where I want to retrieve data from an RSS feed. I can easily retrieve the data I want and get it to show in i.e. a Repeater control.

My problem is, that the blog (Wordpress) that I'm getting the RSS from uses \n for linebreaks which I obviously can't use in HTML. I need to replace these \n with a <br /> tag.

What I've done so far is:

SyndicationFeed myFeed = SyndicationFeed.Load(XmlReader.Create("urltofeed/"));
IEnumerable<SyndicationItem> items = myFeed.Items;
foreach(SyndicationItem item in items)
{
  Feed f = new Feed();
  f.Content = f.ConvertLineBreaks(item.Summary.Text);
  f.Title = item.Title.Text;
  feedList.Add(f);
}
rptEvents.DataSource = feedList;
rptEvents.DataBind();

Then having a Feed class with two properties: Title and Content and a helper-method to replace \n with <br />

However, I'm not sure if this is a good/pretty approach to get data from an RSS feed?

Thanks in advance,

Bo

like image 444
bomortensen Avatar asked Jan 14 '10 18:01

bomortensen


People also ask

Is an RSS feed Worth It?

RSS feeds remain great for an in-depth look at a site's new content — not just the stuff that gets pushed up on social media. If you are genuinely devoted to a site and want to see everything it has to offer, then an RSS feed is still the best way to make sure you don't miss anything.

Are RSS feeds still used 2020?

While RSS feeds are still in use, they're becoming less popular with the use of social media and email subscriptions. Facebook, Twitter, and LinkedIn bring you the latest news from a site if you follow their profile.

What is RSS feed and how do you use it?

An RSS feed is a set of instructions residing on the computer server of a website, which is given upon request to a subscriber's RSS reader, or aggregator. The feed tells the reader when new material—such as a news article, a blog posting, or an audio or a video clip—has been published on the website.


2 Answers

If you are adverse to all the xml parsing in your code you can also run the rss xml schema through xsd and generate a topic and feed class in you code.

This classes should serialize/deserialize to xml. This may be overkill but it's worked great for me when integrating with a standard xml api for a third party.

like image 171
Andy Avatar answered Nov 15 '22 21:11

Andy


Does it have anything to do with the type of rss feed you're consuming?

http://codex.wordpress.org/WordPress_Feeds

like image 33
hunter Avatar answered Nov 15 '22 21:11

hunter