Creating an RSS feed with Dynarex

The following snippet demonstrates how to generate an RSS feed from a Dynarex document.

require 'dynarex'

s =<<EOF
<?dynarex schema="news[title, desc]/entry(title, url)" delimiter=" # "?>
title: James Robertson's blog RSS feed
desc: Find out more about my blog from

A test blog #
Secret sauce #

dynarex =
dynarex.parse s
dynarex.xslt_schema = 'channel[title:title,description:desc]/item(title:title,link:url)'
rss = dynarex.to_rss

puts rss

<rss version='2.0'><channel>
      James Robertson's blog RSS feed</title><description>
      Find out more about my blog from</description><item>
        A test blog</title><link></link></item><item>
        Secret sauce</title><link></link></item></channel></rss>

Note: If you want to limit the number of entries in the RSS feed use the :limit attribute with a value passed into the method to_rss e.g. dynarex.to_rss limit: 10

19-06-2012 22:18