1 Replies - 11940 Views - Last Post: 19 November 2011 - 05:35 AM

#1 heady89  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 164
  • Joined: 31-December 09

How to read xml in asp.net mvc3?

Posted 19 November 2011 - 03:47 AM

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?

Is This A Good Question/Topic? 0
  • +

Replies To: How to read xml in asp.net mvc3?

#2 heady89  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 164
  • Joined: 31-December 09

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:
    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?
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1