Hi,
I've a hard time finding tutorials or explanations on how one would go about to read xml rss in asp.net mvc properly.
I'm simply trying to read an xml rss file from a website and then display the nodes as i wish.
Coming from php where it is extremely straight forward with xml, I find it a bit cryptic in asp.net ...
Could anyone point me in the right direction on give a simple example on how this would be done?
How to read xml in asp.net mvc3?
Page 1 of 11 Replies - 6610 Views - Last Post: 19 November 2011 - 05:35 AM
Replies To: How to read xml in asp.net mvc3?
#2
Re: How to read xml in asp.net mvc3?
Posted 19 November 2011 - 05:35 AM
So i've looked around a bit more and i solved it using this approach:
I created a RSS class with some properties like title,pubbdate etc and then an Rss Reader class like the following:
I then passed this to my view and the view was created as a strongly-type one with a List structure. It all works good, just wondering if this is a good and legit way of doing it?
I created a RSS class with some properties like title,pubbdate etc and then an Rss Reader class like the following:
public class RssReader
{
private static string _xmlURL = "http://.xml";
public static IEnumerable<Rss> GetRssFeed()
{
XDocument feedXml = Xdocument.Load(_xmlURL);
var feeds = from feed in feedXml.Descendants("item")
select new Rss
{
Title = feed.Element("title").Value,
Link = feed.Element("link").Value,
Description = feed.Element("description").Value,
PubDate = feed.Element("pubDate").Value
};
return feeds;
}
}
I then passed this to my view and the view was created as a strongly-type one with a List structure. It all works good, just wondering if this is a good and legit way of doing it?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|