Web technologies -- Laboratory 16 -- 2009-2010 -- info.uvt.ro

Really Simple Syndication (RSS) edit

Is standardised type of feed used to publish frequently updated information such as blog entries, news headlines, audio, and video.

To receive feeds users subscribe to them by entering into the reader the feed's URI. The reader then periodically checks the address for new feeds. You can publish the feed o your website as using the following HTML code:

	<a type="application/rss+xml" href="http://www.yourdomain.com/site.xml"> RSS feed for this site</a>

The site.xml file can be generated automatically by using JSP, PHP, Python or any other server side language. The following example shows how the file can be created using JSPs:

<!-- notice how we changed the content type from the default text/html to text/xml -->
<%@ page contentType="text/xml" %>
<?xml version="1.0" encoding="UTF-8" ?> 

<%-- import needed libraries --%>
<%@ page import="java.util.*, java.text.*, mypackage.rss.*" %>
    
<%-- Generate the RSS XML --%>
<% 
	// You need to define the package and classes which grab the feeds. You could use data from a database
	List rssItems = rssContainer.getAllRSSFeeds();
        
	SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
%>
	<rss version="2.0">
		<channel>
			<title>RSS Title</title>
			<link>http://www.yourdomain.com</link>
			<description>Simple RSS feed</description>
			<lastBuildDate><%= dateFormat.format(Calendar.getInstance().getTime()) %></lastBuildDate> 
			<pubDate><%= dateFormat.format(Calendar.getInstance().getTime()) %></pubDate>
			<%
				Iterator expIt = expList.iterator();
				while (expIt.hasNext()) {
					RSSData rssData = (RSSData)(expIt.next());
			%>
			<item>
				<title> <%= rssData.getTitle() %> </title>
				<description> <%=rssData.getDescription() %></description>
				<link><%= rssData.getLink() %></link>
				<guid><%= UUID.randomUUID().toString() %></guid>
				<pubDate><%= dateFormat.format(rssData.getPublishingData()) %></pubDate>
			</item>
			<%
				}
			%> 
		</channel>
	</rss>

Any appropriate communication protocol (FTP, HTTP, etc) for file retrieval can be used to access the file.

RSS is based on XML. Its file extension can be either .rss or .xml. It requires four main components: title, description, link and enclosure.

The following code fragment shows the content of the previously generated RSS feed:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
	<!-- Every RSS feed needs a distribution channel -->
	<channel>
		<title>RSS Title</title>
		<description>Simple RSS feed</description>
		<link>http://www.yourdomain.com</link>
		<lastBuildDate>Sat, 01 Jan 2011 00:01:00 +0000 </lastBuildDate>
		<pubDate>Sat, 01 Jan 2011 00:01:00 +0000 </pubDate>
 
		<!-- You can have multiple items in a feed. They contain the information you wish others to receive -->
		<item>
			<title>Item title</title>
			<description>Description goes here</description>
			<link>http://www.urltotheitem.com</link>
			<!-- The UUID needs to be unique per item -->
			<guid>UUID</guid>
			<pubDate>Sat, 01 Jan 2011 00:00:01 +0000 </pubDate>
		</item>
	</channel>
</rss>

Before publishing RSS feeds one needs to be sure they validate:

Links edit

Exercises edit