Two ways to generate RSS - rss/maker and rss/2.0 - which is better?

J

Jonathan Groll

From some fiddling I've found that there are two ways to generate RSS
using the rubyRSS libraries shipped with ruby 1.8.7.

Neither method seems ideal for generating RSS 2.0 (the RSS XML
produced seems to be missing tags/attributes that I would like in both
cases). Is there something that I'm missing and is there a preferred
method?

In particular, I would like to use the 'guid' attribute with rss/maker
but it seems to be unsupported? Surely there are some feed readers who
depend on this for determining if an item is unique? It does seem the
'guid' is a part of the RSS 2.0 standard.

However, if I were to use the rss/2.0 method, I could specify the
guid, but would lose the <dc:date> attribute and all of the xmlns
definitions at the top. Also with rss/2.0 I couldn't work out how to
do a reverse sort of items (is this even needed though).

Any comments?

Method 1: rss/maker, simplest example:

#!/usr/bin/env ruby
require 'rss/maker'

if __FILE__ == $0
content = RSS::Maker.make('2.0') do |m|
m.channel.title = "title"
m.channel.about = "about" # <<<=seems to not be used
m.channel.link = "www.example.com"
m.channel.description = "desc"
m.items.do_sort = true # <<<= sort items by date

2.times do |n|
i = m.items.new_item
i.title = "title"
i.link = "www.example.com/" + n.to_s
# i.guid = <<<=Not supported
i.description = "Main body"
i.date = Time.now
end
end

puts content.to_s
end

Outputs:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<channel>
<title>title</title>
<link>www.example.com</link>
<description>desc</description>
<item>
<title>title</title>
<link>www.example.com/1</link>
<description>Main body</description>
<pubDate>Fri, 26 Jun 2009 16:35:31 +0200</pubDate>
<dc:date>2009-06-26T16:35:31.598452+02:00</dc:date>
</item>
<item>
<title>title</title>
<link>www.example.com/0</link>
<description>Main body</description>
<pubDate>Fri, 26 Jun 2009 16:35:31 +0200</pubDate>
<dc:date>2009-06-26T16:35:31.592903+02:00</dc:date>
</item>
</channel>
</rss>

Method 2: rss/2.0, simplest example:

#!/usr/bin/env ruby

require 'rss/2.0'
if __FILE__ == $0

content = RSS::Rss.new('2.0')
channel = RSS::Rss::Channel.new

channel.title = "title"
channel.link = "www.example.com"
channel.description = "desc"
#channel.item.do_sort = true "<<<=Cannot sort

2.times do |n|
i = RSS::Rss::Channel::Item.new
i.title = "title"
i.link = "www.example.com/" + n.to_s
i.guid = RSS::Rss::Channel::Item::Guid.new
i.guid.content = n.to_s
i.guid.isPermaLink = true
i.description = "Main body"
i.date = Time.now
channel.items << i
end

content.channel = channel
puts content.to_s

end

Outputs:
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>title</title>
<link>www.example.com</link>
<description>desc</description>
<item>
<title>title</title>
<link>www.example.com/0</link>
<description>Main body</description>
<pubDate>Fri, 26 Jun 2009 16:39:37 +0200</pubDate>
<guid isPermaLink="true">0</guid>
</item>
<item>
<title>title</title>
<link>www.example.com/1</link>
<description>Main body</description>
<pubDate>Fri, 26 Jun 2009 16:39:37 +0200</pubDate>
<guid isPermaLink="true">1</guid>
</item>
</channel>
</rss>

Regards,
Jonathan Groll.
 
K

Kouhei Sutou

Hi,

In <[email protected]>
"Two ways to generate RSS - rss/maker and rss/2.0 - which is better?" on Fri, 26 Jun 2009 23:52:37 +0900,
Jonathan Groll said:
From some fiddling I've found that there are two ways to
generate RSS
using the rubyRSS libraries shipped with ruby 1.8.7.

Neither method seems ideal for generating RSS 2.0 (the RSS
XML
produced seems to be missing tags/attributes that I would
like in both
cases). Is there something that I'm missing and is there a
preferred
method?

Use RSS Maker. It generates RSS 2.0 object.
In particular, I would like to use the 'guid' attribute with
rss/maker
but it seems to be unsupported? Surely there are some feed
readers who
depend on this for determining if an item is unique? It does
seem the
'guid' is a part of the RSS 2.0 standard.

RSS Maker support 'guid' but it's not 'guid=' method.
# i.guid = <<<=Not supported

i.guid.content = 'xxx'
i.guid.isPermaLink = true

generates

<guid isPermaLink="true">xxx</guid>


Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top