views:

510

answers:

2

I am trying to parse an RSS feed using Linq to XML like so:

        XNamespace slashNamespace = "http://purl.org/rss/1.0/modules/slash/"; 
        XDocument rssFeed = XDocument.Load(@"http://blog.daimokuchart.com/index.php/feed/");

        var posts = from item in rssFeed.Descendants("item")
                    select new RSSData {
                        Title = item.Element("title").Value,
                        Published = DateTime.Parse(item.Element("pubDate").Value),
                        Url = item.Element("link").Value,
                        Content = item.Element("content:encoded").Value
                    };

However; it is having a problem with with the content:encoded item I get this error "The ':' character, hexadecimal value 0x3A, cannot be included in a name. "

How the heck to I parse this item element?

+2  A: 
XNamespace nsContent = "http://purl.org/rss/1.0/modules/content/";

// ...

Content = item.Element(nsContent + "encoded").Value

// ...
Tomalak
A: 

There is a much simpler way to parse a RSS feed : the SyndicationFeed class

More details here

Thomas Levesque
Basically the same thing except with a different class
dswatik
Yes, except that you don't have to worry about the actual XML schema...
Thomas Levesque