DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

RSS2 Rxml Template

08.05.2005
| 16599 views |
  • submit to reddit
        Some of the rxml RSS 2 templates posted here will work, but have small validation problems. As far as I can tell, this one passes validation every time, given an instance variable @posts, with the appropriate methods. From the source of blinksale.com:

xml.instruct!

xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
  xml.channel do

    xml.title       "Feed Name"
    xml.link        url_for :only_path => false, :controller => 'posts'
    xml.pubDate     CGI.rfc1123_date @posts.first.updated_at if @posts.any?
    xml.description "Feed Description"

    @posts.each do |posts|
      xml.item do
        xml.title       post.name
        xml.link        url_for :only_path => false, :controller => 'posts', :action => 'show', :id => post.id
        xml.description post.body
        xml.pubDate     CGI.rfc1123_date post.updated_at
        xml.guid        url_for :only_path => false, :controller => 'posts', :action => 'show', :id => post.id
        xml.author      "#{post.author.email} (#{post.author.name})"
      end
    end

  end
end