Windows Phone App Studio – Part 2 – RSS Reader Fix

Start Using App Studio

If you have not tried the Windows Phone App Studio, you should give it a try. It is a simple online tool that allows anyone to build a Windows Phone app with a few clicks of a button.

It predominantly relies on hooking up RSS Feeds, YouTube channels or seaches, Bing searches and Flickr queries. There are some other features such as adding HTML or a DataCollection to store data, all of which serve its purpose, to have the ability to create a quick and simple app.

In Part 2 we will look into some of the limitations of Windows Phone App Studio and look at a few easy ways to correct them. If you have not looked over Part 1, you can and follow along.

 

 

 

Prerequisites

Beyond the first part of the tutorial series, it is assumed that you are familar with development as well as developing for Windows 8. The following items are needed to follow along with the rest of the series.

Windows 8.1

Visual Studio 2013

Windows Store Developer Account

More information can be found at the getting started page for Windows Store App Development and Windows Phone App Development.

App Studio Limitations

When I started creating a few apps, I found some limitations rather quickly. The first one is on the design side with the set of templates that are provided. There are a few “predefined” templates that will allow you to arrange your content the way you like it. However, if you were adding a Data Collection or an RSS feed/Search and wanted a few more fields that are returned to display on the template, you are out of luck.

The other big limitation is the RSS Feed data source and using WordPress or any blogs that support RSS 2.0.11 with the content:encoded field.

As you can see in the example image, the full “content” or the article of the RSS Feed is never displayed. We are left with the [..] truncating where we should have the full article.

This has to do with the logic of the code and the parsing of the XML document.

There are a few other limitations such as HTML not displaying all of the elements, encoded characters displaying and some others.

We will focus on the RSS feed for part 2.

Fixing RSS

The first thing we need to do is “Generate” our project and download the source code. It does not matter if you download the Windows Phone project or the Windows Phone 8.1 and Windows 8.1 project. To review how to “Generate”, take a look at Part 1 of the Tutorial.

Once downloaded, open the project up in Visual Studio 2013 and you will see all of the files the App Studio generates. There are a lot of things going on in this solution but I am only going to cover a few of them to fix our issues defined above.

visual studio project

First we want to navigate to our AppStudio.Data project and go to DataProviders > RssReaders and open RssReader.cs.

This is where the problem lies with not displaying our content fully.

 

 

 

 

 

RSS Reader  ParseItemSearch for the method ParseItem and we will step through the code.

The first thing it is doing is creating an object of RssSchema. This shcema defined in the DataSchemas folder. We do not need to change anything to that file, however, it probably would be good to look at and make sure it has everything your RSS XML document is returning. For this purpose it is just fine.

The next couple of lines are getting the value for “title” and “link”. The code is using a helper method called GetSafeElementString and returns the value of the XElement.

Issue 1:

The next line is getting the “description” element and storing it in a string. If this string is NULL or Empty then it looks for the “content” element. If not then it moves along and eventually stores the “description” in the rssITem.Content property. This is where the first problem is seen. Chances are “description” will never be NULL and the “decription” will always be stored in the rssItem.Content property. Which is what we might not want.

“Description” is an element of the <item> tag that is defined in the RSS Feed. Description is used for the synopsis of an article/story. As defined by the RSS Board:

An item MAY contain the following child elements: authorcategory,
commentsdescriptionenclosure,
guidlinkpubDatesource and title. All of these elements are OPTIONAL but an item MUST contain either a title or description.

If the publisher chooses to use “description” as a synopis or summary, then the code that is will NEVER allow the full article to be shown. We will put in a fix that will work no matter what and use the properties in the RSS Schema correctly.

Issue 2:

The other problem is if the “description” is NULL or Empty, the content element is then searched to find the full article. The problem here is it is not found when parsing through the XML. The reason it is not found is due to the namespace that is specified for the content element. T

The “content” element is actually in the namespace http://purl.org/rss/1.0/modules/content/ and is returned via “content:encoded”. Most WordPress blogs use the “description” as a summary and “content” as the full blog post. If we keep the code as is, we will never get the full article.

While we are here, you can see line where it is truncating at 500 characters for the summary. If you want to change that to be more or less, feel free.

The Fix

How do we fix this? Simple, lets rewrite the code but in reverse order to take account of both elements.

The RSS Board states the following:

When an item contains both elements (description and content), six of the eight aggregators display content:encoded and ignore description. FeedDemon displays the element defined last within the item element and Firefox 2.0 doesn’t support descriptions.

Publishers who don’t want to employ item summaries in their feeds SHOULD use the description element for an item’s full content rather than content:encoded because it has the widest support.

Publishers who employ summaries SHOULD store the summary in description and the full content in content:encoded, ordering description first within the item. On items with no summary, the full content SHOULD be stored in description.

It sounds like “description” is the standard for full articles, however, WordPress blogs use description as summary and content as full article. I will try to structure it that the code will work with both.

I am first going to get the content element. Getting the content first allows me to check to see if I have a full article or not and my fallback would be to use description as the content. I mentioned above that parsing content usually returns NULL, that is becuase there is no namespace to help the parser. I will now pass the proper namespace for the content element and look for the “encoded” attribute instead. This now returns the full content.

The next step is to get the “content” element to determine if there is anything in there.

We did not dive deep into the method GetSafeElementString but basically you can pass in an element name and it uses the default namespace to traverse and find the element specified. In our case for content, it is not part of the default namespace. I am passing it in. We will clean that up later.

I will now check to see if any content was returned using the namespace. If there is nothing returned, I will fallback and look for the content element without the namespace.

It still might be empty, which is completely normal for some RSS feeds (as stated above) so I will now go look for description. Descriptions are usually there so I won’t perform any checks on that. I could but if there is no content and no description then most likely you have an app that nobody would want or an RSS feed that you should not be using.

The next line performs a check on the content variable to see if it is NULL or Empty. Then it sanitizes the string to use and sets the rssItem.Content.

This way, if content is NOT NULL then content is stored otherwise it will use description. Again, description should not be null and if it is, I would reccommend trying an different RSS Feed.

The last 2 lines stay the same as the original method, cleaning up any HTML and storing it in the rssITem.Summary.

Whats Next

That is it. Now you have a fully functioning blog reader app.

Visit Part 1 for the Getting Started tutorial.

Part 3 will be focusing on cleaning up the XAML and making it work for your application.

Download RssReader.cs