locked
RSS.XML reader

Answers

  • Hello,

    Please find below an example of passing rss.xml files using the sample above.

    1. Class definitions of feed data and feed item.

    public class FeedItem { public string Title { get; set; } public string Author { get; set; } public string Content { get; set; } public DateTime PubDate { get; set; } public Uri Link { get; set; } public String type { get; set; } public string ImagePath { get; set; } }

    public class FeedData { public string Title { get; set; } public string Description { get; set; } public DateTime PubDate { get; set; } private List<FeedItem> _Items = new List<FeedItem>(); public List<FeedItem> Items { get { return this._Items; } } }

     2. Read and Process Feeds

        public class RSSFeeds
        {
    
            public async Task GetFeedAsync(string feedUriString)
            {
                // using Windows.Web.Syndication;
                SyndicationClient client = new SyndicationClient();
                Uri feedUri = new Uri(feedUriString);
    
                try
                {
                    SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);
                    FeedData feedData = new FeedData();
                    feedData.Title = feed.Title.Text;
    
                    foreach (SyndicationItem item in feed.Items)
                    {
                        FeedItem feedItem = new FeedItem();
                        feedItem.Title = item.Title.Text;
                        feedItem.PubDate = item.PublishedDate.DateTime;
                        feedItem.Author = item.Authors[0].Name.ToString();
                        if (feed.SourceFormat == SyndicationFormat.Atom10)
                        {
                            feedItem.Content = item.Content.Text;
                        }
                        else if (feed.SourceFormat == SyndicationFormat.Rss20)
                        {
                            feedItem.Content = item.Summary.Text;
                        }
                        feedData.Items.Add(feedItem);
                    }
                    //this.DataContext = feedData;
                    //ItemListView.SelectedIndex = 0;
                }
                catch (Exception ex)
                {
                    // Log Error.
                    //TitleText.Text = ex.Message;
                }
            }
    
    
        }


    3. Calling GetFeedAsync and pass an RSS.

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
      String FeedUri="http://feeds.popsci.com/c/34567/f/632419/index.rss";
       await new RSSFeeds().GetFeedAsync(FeedUri);
    }

    Hope it helps! 

    Tuesday, February 11, 2014 7:22 PM

All replies

  • This should work for both RSS and Atom feeds:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh452994.aspx

    • Proposed as answer by Dave SmitsMVP Sunday, February 09, 2014 1:17 PM
    Sunday, February 09, 2014 12:43 PM
  • Chervine,

    No - because the url mentioned by you is reading web feeds having the file extension ".aspx" while I am trying to read web feeds having the file extension ".xml"


    QSS - QSOFT Solution, (we deliver quality software)

    Tuesday, February 11, 2014 1:03 PM
  • Hello,

    Please find below an example of passing rss.xml files using the sample above.

    1. Class definitions of feed data and feed item.

    public class FeedItem { public string Title { get; set; } public string Author { get; set; } public string Content { get; set; } public DateTime PubDate { get; set; } public Uri Link { get; set; } public String type { get; set; } public string ImagePath { get; set; } }

    public class FeedData { public string Title { get; set; } public string Description { get; set; } public DateTime PubDate { get; set; } private List<FeedItem> _Items = new List<FeedItem>(); public List<FeedItem> Items { get { return this._Items; } } }

     2. Read and Process Feeds

        public class RSSFeeds
        {
    
            public async Task GetFeedAsync(string feedUriString)
            {
                // using Windows.Web.Syndication;
                SyndicationClient client = new SyndicationClient();
                Uri feedUri = new Uri(feedUriString);
    
                try
                {
                    SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);
                    FeedData feedData = new FeedData();
                    feedData.Title = feed.Title.Text;
    
                    foreach (SyndicationItem item in feed.Items)
                    {
                        FeedItem feedItem = new FeedItem();
                        feedItem.Title = item.Title.Text;
                        feedItem.PubDate = item.PublishedDate.DateTime;
                        feedItem.Author = item.Authors[0].Name.ToString();
                        if (feed.SourceFormat == SyndicationFormat.Atom10)
                        {
                            feedItem.Content = item.Content.Text;
                        }
                        else if (feed.SourceFormat == SyndicationFormat.Rss20)
                        {
                            feedItem.Content = item.Summary.Text;
                        }
                        feedData.Items.Add(feedItem);
                    }
                    //this.DataContext = feedData;
                    //ItemListView.SelectedIndex = 0;
                }
                catch (Exception ex)
                {
                    // Log Error.
                    //TitleText.Text = ex.Message;
                }
            }
    
    
        }


    3. Calling GetFeedAsync and pass an RSS.

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
      String FeedUri="http://feeds.popsci.com/c/34567/f/632419/index.rss";
       await new RSSFeeds().GetFeedAsync(FeedUri);
    }

    Hope it helps! 

    Tuesday, February 11, 2014 7:22 PM