I'm currently developing an MVC project which contains an RSS feed reader.
The current method is reading XML Files with the Syndication library, although it doesn't support all of the feed types and i couldn't figured out how can i add the SyndicationFeed Entity to my DB (MSSQL 2012) with code first migration due to a key problem (Already asked a Q about it with no answer: Syndication keys missing MVC) so i just made a feed model that gets its content from the Syndication items. Any suggestions on how or should i continue using it or even switching to a different way of work?
This is the way i get and save the feeds:
XmlReader reader = XmlReader.Create(site.RssUrl);
SyndicationFeed feed = SyndicationFeed.Load(reader);
var FeedList = feed.Items.ToList();
foreach (var item in FeedList)
{
var dupCheck = db.Feeds.FirstOrDefault(f => f.Title == item.Title.Text);
if (dupCheck == null)
{
var newFeed = new Feeds() { Date = DateTime.Now.ToString(), SiteId = site.SiteId };
if (item.Title != null) newFeed.Title = item.Title.Text;
if (item.Summary != null) newFeed.Description = item.Summary.Text;
if (item.PublishDate != null) newFeed.PubDate = item.PublishDate.ToString();
if (item.Links != null) newFeed.Link = item.Links[0].Uri.ToString();
if (feed.ImageUrl != null) newFeed.ImageUrl = feed.ImageUrl.ToString();
db.Feeds.Add(newFeed);
if (item.Categories.Count != 0)
foreach (var category in item.Categories)
if (db.Categories.FirstOrDefault(cat => cat.Name == category.Name) == null)
{
var NewCategory = new Categories() { Name = category.Name };
NewCategory.Feeds.Add(newFeed);
db.Categories.Add(NewCategory);
}
else
db.Categories.First(cat => cat.Name == category.Name).Feeds.Add(newFeed);
db.SaveChanges();
}
This is the Feed Model:
public class Feeds
{
[Key]
public int FeedId { get; set; }
public string ImageUrl { get; set; }
public string Link { get; set; }
[DataType(DataType.MultilineText)]
[AllowHtml]
public string Title { get; set; }
[DataType(DataType.MultilineText)]
[AllowHtml]
public string Description { get; set; }
public string PubDate { get; set; }
public string Date { get; set; }
public int SiteId { get; set; }
}
After reading a hell lot about it, i came to realize that the XML feed method is a dying one, and there might be some better and more useful and growing alternatives that i should use for the purpose of reading feeds (The Twitter list for example)...
So the other more general question is: should i go ahead and continue with the XML reader? or should i consider a different methodology knowing that the XML rss type will probably die sooner or later (or am i mistaken in this case)?
Thanks in advance!
I'm currently on the same journey as you are in trying to read RSS 0.92, 0.95, 2.0 formats via SyndicationFeed methods and exploring the challenge of integrating these "old" standards with increasingly popular Twitter formats in order to build a news aggregator. Thus, I don't profess to be an expert; however, my research suggests that your SyndicationFeed entity approach with building your own intermediate Syndication objects and datareaders (rather than try to do this via CodeFirst migration) is the correct approach. Once you have the objects in place, you can likely shoehorn Twitter feeds into these objects as well.