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 jamesrobertson.eu

A test blog # http://jamesrobertson.eu/blog/test-blog.html
Secret sauce # http://jamesroberton.eu/blog/secret-sauce.html
EOF

dynarex = Dynarex.new
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>
      <title>
      James Robertson's blog RSS feed</title><description>
      Find out more about my blog from jamesrobertson.eu</description><item>
      <title>
        A test blog</title><link>
        http://jamesrobertson.eu/blog/test-blog.html</link></item><item>
      <title>
        Secret sauce</title><link>
        http://jamesroberton.eu/blog/secret-sauce.html</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

Tags:
Source:
2218hrs.txt
Published:
19-06-2012 22:18