Creating Your Own RSS Feed

My friend Josh Wagner, network admin for CTG and famed author of the Periphery Stowe series, recently inquired about RSS feeds. I thought I would take a moment to publish an article on RSS and how to create your own. In my example, I wrote the syntax in PHP but you could easily translate this logic to any programming or scripting language.

RSS feeds are rather simple and standardized format for listing articles.

CREATING YOUR OWN RSS FEED:

See http://www.mikesparr.com/rss

You’ll notice the markup. If you wanted to syndicate your site’s content, simply write a script that loops through the last X articles and in your script, you can output the xml for your article. For example, in PHP I would:

// "n" is new line and the period (.) is the string concatonator in PHP
// (like plus [+] in Java or ampersand [&] in Visual Basic)

$rss_output = ‘’;

$rss_output .= ‘<rss version="0.92">’ . “n”;
$rss_output .= ‘  <channel>’ . “n”;
$rss_output .= ‘    <title>Mike Sparr's Personal Website</title>’ . “n”;
$rss_output .= ‘    <link>http://www.mikesparr.com</link>’ . “n”;
$rss_output .= ‘    <description>’ . “n”;
$rss_output .= ‘    E-Commerce, Technology, Business and Personal and Travel Information’ . “n”;
$rss_output .= ‘    </description>’ . “n”;
$rss_output .= ‘    <lastBuildDate>Sun, 01 Oct 2006 06:17:20 +0000</lastBuildDate>’ . “n”;
$rss_output .= ‘    <language>en</language>’ . “n”;

// here I would iterate through a list of articles and dynamically
// populate the text between the tags.  for this demo I simply hard-coded values
$rss_output .= ‘    <item>’ . “n”;
$rss_output .= ‘      <title>' . "Greetings From London" . '</title>’ . “n”;
$rss_output .= ‘      <description>’ . “n”;
$rss_output .= ‘      Well thank goodness I’m not in Italy right now, or my flight may not be able to return’ .
                      ‘ to the United States.  If you haven’t heard, the temporary passenger information ‘ .
                      ‘sharing between the US and EU has expired and EU nations are hesitant to renew or agree for ‘ .
                      ‘ longer terms.  UK has issued [...]’ . “n”;
$rss_output .= ‘      </description>’ . “n”;
$rss_output .= ‘      <link>’ . “n”;
$rss_output .= ‘      http://www.mikesparr.com/2006/10/01/greetings-from-london/’ . “n”;
$rss_output .= ‘      </link>’ . “n”;
$rss_output .= ‘    </item>’ . “n”;

// close everything back up
$rss_output .= ‘  </channel>’ . “n”;
$rss_output .= ‘</rss>’ . “n”;

// output contents
echo $rss_output;

As far as reading others’ RSS feeds, you would have to invoke an HTTP request and retrieve the above. You can then manually look through and parse out contents given it’s a standardized format, or search the internet for libraries for RSS reading. Various languages have an XML library allowing your to traverse through an XML documents nodes and output content.

I hope this helps you out. I would go to http://www.w3schools.com for tutorials if you need more.

Mike

1 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 5 (1 votes, average: 5 out of 5)
Loading ... Loading ...


Leave a Reply

You must be logged in to post a comment.