RSS Reader 2.0

RSS Reader 2.0

Using the Visual Studio integrated development environment and the C# programming language, we will develop a cross-platform mobile application for reading news feeds (RSS) from internet sources.

circle-info

Information

RSS is a software mechanism for exchanging news between websites or between a site and a user. It represents a set of formats for delivering information from the World Wide Web.

Start

  1. Launch the Visual Studio integrated development environment.

  2. Create a new project: Visual C# > Cross-Platform > Mobile App (Xamarin.Forms).

  3. Name the project: RSS Reader 2.0.

FeedReader.cs

Add a new class named FeedReader.cs, which will be used to store data from the news feed.

/// <summary>
/// RSS Feed Item
/// </summary>
public class FeedItem
{
    public string Title { get; set; }
    public string Description { get; set; }
    public string Link { get; set; }
    public string PubDate { get; set; }
}

/// <summary>
/// RSS Feed Reader
/// </summary>
public class FeedReader
{
        public IEnumerable<FeedItem> ReadFeed(string url)
        {
            var feed = XDocument.Load(url);
            var posts = from item in feed.Descendants("item")
                        select new FeedItem
                        {
                            Title = item.Element("title").Value,
                            Description = item.Element("description").Value,
                            Link = item.Element("link").Value,
                            PubDate = item.Element("pubDate").Value
                        };
            return posts;
        }
}

HyperlinkButton.cs

Add a HyperlinkButton.cs class that will be used to add hyperlinks to the application's user interface, following Microsoft documentation: Xamarin.Forms Hyperlinks Microsoft Docsarrow-up-right

MainPage.xaml

The MainPage.xaml file contains the source code for the application's user interface design and is written in XAML. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.

MainPage.xaml.cs

The MainPage.xaml.cs file contains the source code for the application's business logic and is written in C#. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.

Demo

Run the application from the menu: Debug > Start Debugging or by pressing the F5 key.

Fig. 2.62 Testing the cross-platform mobile application for reading internet news feeds (RSS sources) - Android Emulator 11 (API 30).

Last updated