tags:

views:

20

answers:

1

Hi, I have a problem for parsing a rss feed using c#. I used to use this method to load the feed. XDocument rssFeed = XDocument.Load(@url); But, when I notice when the feed has a xml-stylesheet this method crashes saying the xml is not well formated... Here's a rss feed that contains this tag http://www.channelnews.fr/accueil.feed?type=rss

What would be the best way to parse any rss feed using c#?

Thanks for your help

+1  A: 

This code works for me

    static XDocument DownloadPage()
    {
        var req = (HttpWebRequest)WebRequest.Create("http://www.channelnews.fr/accueil.feed?type=rss");
        req.UserAgent = "Mozilla";

        using(var response = req.GetResponse())
        using(var stream = response.GetResponseStream())
        using (var reader = new StreamReader(stream))
            return XDocument.Load(reader);
    }

Note, that if you omit setting UserAgent, then response will contain string 'DOS' that is defnintly not xml :)

desco
Yes it was this...I missed the UserAgent...Thanks...Stan
Stan92