Reading RSS feed using visual C #

I am trying to read an RSS feed and display C # in my application. I used the code below and it works great for other RSS feeds. I want to read this RSS feed ---> http://ptwc.weather.gov/ptwc/feeds/ptwc_rss_indian.xml and the code below does not work for it. I don't get any errors, but nothing happens, the text box that I want the displayed RSS feed to be empty. Please help. What am I doing wrong?

    public class RssNews
    {
        public string Title;
        public string PublicationDate;
        public string Description;
    }

    public class RssReader
    {
        public static List<RssNews> Read(string url)
        {
            var webResponse = WebRequest.Create(url).GetResponse();
            if (webResponse == null)
                return null;
            var ds = new DataSet();
            ds.ReadXml(webResponse.GetResponseStream());

            var news = (from row in ds.Tables["item"].AsEnumerable()
                        select new RssNews
                        {
                            Title = row.Field<string>("title"),
                            PublicationDate = row.Field<string>("pubDate"),
                            Description = row.Field<string>("description")
                        }).ToList();
            return news;
        }
    }


    private string covertRss(string url) 
    {
        var s = RssReader.Read(url);
        StringBuilder sb = new StringBuilder();
        foreach (RssNews rs in s)
        {
            sb.AppendLine(rs.Title);
            sb.AppendLine(rs.PublicationDate);
            sb.AppendLine(rs.Description);
        }

        return sb.ToString();
    }

// Form Download code ///

 string readableRss;
 readableRss = covertRss("http://ptwc.weather.gov/ptwc/feeds/ptwc_rss_indian.xml");
            textBox5.Text = readableRss;
+5
source share
1 answer

It appears that the DataSet.ReadXml method failed because the category is listed twice in the element, but in a different namespace.

This works better:

public static List<RssNews> Read(string url)
{
    var webClient = new WebClient();

    string result = webClient.DownloadString(url);

    XDocument document = XDocument.Parse(result);

    return (from descendant in document.Descendants("item")
            select new RssNews()
                {
                    Description = descendant.Element("description").Value,
                    Title = descendant.Element("title").Value,
                    PublicationDate = descendant.Element("pubDate").Value
                }).ToList();
}
+8
source

All Articles