Displaying items from external RSS feeds

   —   

RSS feeds represent one of the ways to distribute content online. In this article you will learn how to display articles from an external RSS feed in Kentico. It also covers troubleshooting some of the issues that you may encounter with some RSS feeds in older versions of Kentico.

Setting it up

The basic setup requires you to add two web parts on a page, RSS data source and Basic repeater. In the RSS data source you have to enter the value for RSS feed URL, and set the Basic Repeater’s data ource name to the ID of the RSS data source. Then select, or create, a transformation for the Transformation Name property of the Basic Repeater.

You can see an example of such a transformation below:

<h2> <a href="<%# Eval("link")%>"> <%# Eval("title") %> </a> </h2> <p> <strong>Published</strong>: <%# Eval("pubdate") %> </p> <p> <%# Eval("description") %> </p> <br/>

After this is done, the page will be populated with content from the RSS feed. If you need to know more details about configuring the web parts, please refer to our documentation for Kentico 7, Kentico 8.2, or Kentico 9.

What if it doesn’t work?

It may happen that the data source web part is not able to process the given RSS feed. This could be the case in Kentico 7 with some RSS feeds. Such an issue is much less likely in more recent versions, but is still possible as there are no strict limitations to what an RSS feed can contain. If you have set everything correctly and nothing shows, there will be an event in the Kentico Event Log application. The RSS Data Source web part logs every problem. Therefore, if your repeater does not show any data, your best option is to start determining the issue by looking into the Event Log.

Message: A column named ‘…’ already belongs to this DataTable

rsseventdetails.png

When you encounter the error above, or similar for a different column, the issue is that the XML markup of the RSS feed contains two elements with the same field name at different levels of the XML. The XML Data Source in Kentico does not handle that scenario well in version 7, as it does not allow duplicate fields with the same name. You can fix the problem by telling Kentico what syntax to look for. This can be done by providing an XSD schema for the RSS Data Source web part. It has a special property named RSS feed custom XSD schema URL.

XSD provides the syntax and defines a way in which elements and attributes can be represented in an XML document. It also advocates that the given XML document should be of a specific format and specific data type. XSD is fully recommended by W3C consortium as a standard for defining an XML Document.

Here is an example of a simple XSD schema that you may use:

<?xml version="1.0" encoding="utf-8"?> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:app1="http://www.w3.org/2005/Atom"> <xs:element name="item"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string" minOccurs="0" /> <xs:element name="author" type="xs:string" minOccurs="0" /> <xs:element name="description" type="xs:string" minOccurs="0" /> <xs:element name="pubDate" type="xs:string" minOccurs="0" /> <xs:element name="link" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

An XSD schema can be created in Visual Studio as per the instructions available in the article How to: Create an XML Schema from an XML Document on MSDN. You can find a more detailed description of XSD together with its advantages and further examples in Understanding XSD Schema article on codeguru.com.

Since the data source property requires a URL to the XSD schema, it is needed to upload the xml file online. It could be placed in the content tree in the Pages application as a File page type, or on a cloud-based hosting service of your choice. The link has to be publicly available. Once you have it, set it as a custom XSD schema URL in the RSS data source. The repeater should now show the articles from given RSS feed.

Message: The remote name could not be resolved: 'www.example.com'

If you see errors such as “The remote name could not be resolved” or “The remote server returned an error: (500) Internal Server Error”, the problem is in the configuration of services outside of Kentico such as Windows IIS. It is possible that there is a firewall in place which is restricting the access of the Kentico instance as well. You may try to determine the problem by using Fiddler or a similar tool; however, we recommend consulting the issue with your system administrator.

Share this article on   LinkedIn Google+