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
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.
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.
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.
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.
Does it have anything to do with the type of rss feed you're consuming?
http://codex.wordpress.org/WordPress_Feeds
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With