# Atom & the Standard Library RSS Module

**URL:** <https://www.ruby-forum.com/t/atom-the-standard-library-rss-module/133918>\
**Category:** Ruby\
**Created:** [April 4, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/atom-the-standard-library-rss-module/133918 "2008-04-04T23:25:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![grant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@grant](https://www.ruby-forum.com/u/grant)\
**Post date:** [April 4, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/atom-the-standard-library-rss-module/133918/1 "2008-04-04T23:25:55Z")

</div>

I need to parse RSS 1.0, 2.0 and ATOM feeds. I upgraded my RSS module  
to the latest version (0.2.4) to get ATOM support. The strange thing  
is that the data structure returned for ATOM feeds is ugly and wildly  
inconsistent with the nice, clean one that is returned for RSS feeds.

I’ve noticed there are a couple of competing Ruby ports of Mark  
Pilgrim’s Universal Feedparser. The ‘rfeedparser’ one looks to be the  
best and FeedTools looks interesting, but I haven’t actually tried  
them yet. (I really like the Universal Feedparser for Python.)

Does anyone have any suggestions on which direction to take?

---

<div class="post-metadata">

**Author:** ![grant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@grant](https://www.ruby-forum.com/u/grant)\
**Post date:** [April 5, 2008, 2:30am UTC](https://www.ruby-forum.com/t/atom-the-standard-library-rss-module/133918/2 "2008-04-05T02:30:51Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Atom & the Standard Library RSS Module” on Sat, 5 Apr 2008 06:25:05  
+0900,  
grant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I need to parse RSS 1.0, 2.0 and ATOM feeds. I upgraded my RSS module  
> to the latest version (0.2.4) to get ATOM support. The strange thing  
> is that the data structure returned for ATOM feeds is ugly and wildly  
> inconsistent with the nice, clean one that is returned for RSS feeds.

Please show an example.

---

<div class="post-metadata">

**Author:** ![grant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@grant](https://www.ruby-forum.com/u/grant)\
**Post date:** [April 5, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/atom-the-standard-library-rss-module/133918/3 "2008-04-05T13:45:59Z")

</div>

On 5 Apr, 01:29, Kouhei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Please show an example.

Sorry, I got tangled up in my own wishes. My problem with the library  
was just in my head. I suppose I was just hoping for a more consistent  
representation of a feed than I’ve had to deal with in the past. I  
know that what is generated by RSS/ATOM parsing libraries is a  
reflection of the feeds themselves.

Anyway, a few examples of what bugs me, demonstrated in irb:

require ‘rss’

rss = ‘[http://www.giftedslacker.com/feed/](http://www.giftedslacker.com/feed/)’  
atom = ‘[OBLIVIONATION](http://oblivionation.blogspot.com/feeds/posts/default)’

rssfeed = RSS::Parser.parse(rss)  
atomfeed = RSS::Parser.parse(atom)

#print the content of the most recent post  
puts rssfeed.items[0].content\_encoded  
puts atomfeed.items[0].content.content

#print the titles of the posts in the feed  
rssfeed.items.each {|item| puts item.title}  
atomfeed.items.each {|item| puts item.title.content}

#print the author of the most recent post  
rssfeed.items[0].dc\_creator  
atomfeed.entries[0].author.name.content

* * *

What I’d like is a consistent interface to the commonly used elements  
in ATOM and RSS feeds, regardless of version. It must be more  
difficult than it seems to me, because I’m not aware that anyone does  
it. I might give it a try just for fun. But, being new to Ruby, I’m  
not sure where to begin.

-grant

---

<div class="post-metadata">

**Author:** ![grant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@grant](https://www.ruby-forum.com/u/grant)\
**Post date:** [April 6, 2008, 4:33am UTC](https://www.ruby-forum.com/t/atom-the-standard-library-rss-module/133918/4 "2008-04-06T04:33:04Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: Atom & the Standard Library RSS Module” on Sat, 5 Apr 2008  
20:45:06 +0900,  
grant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> require ‘rss’
> 
> rss = ‘[http://www.giftedslacker.com/feed/](http://www.giftedslacker.com/feed/)’  
> atom = ‘[OBLIVIONATION](http://oblivionation.blogspot.com/feeds/posts/default)’
> 
> rssfeed = RSS::Parser.parse(rss)  
> atomfeed = RSS::Parser.parse(atom)

You can normalize parsed feed by to\_rss, to\_atom or  
to\_xml. For example:

rss10feed = atomfeed.to\_rss(“1.0”)

You may need to set default value:

rss10feed = atomfeed.to\_rss(“1.0”) do |maker|  
maker.channel.about ||= maker.channel.link  
maker.channel.description ||= “No description”  
maker.items.each do |item|  
item.title ||= “UNKNOWN”  
item.link ||= “UNKNOWN”  
end  
end

> atomfeed.entries[0].author.name.content  
> The atom specification says that all atom element may have  
> xml:base and xml:lang attributes. If  
> RSS:⚛:Entry::Author#name returns a String, we can’t  
> get such attribute values. This is why  
> RSS:⚛:Entry::Author#name returns an  
> RSS:⚛:Entry::Author::Name not a String.

BTW, what about the following API?

atomfeed.entries[0].author.name # =\> a String  
atomfeed.entries[0].author.name do |name|  
# name: a  
RSS:⚛:Entry::Author::Name  
name.content # =\> a String  
end # =\> the last evaluated value (name.content)

Thanks,

---

<div class="post-metadata">

**Author:** ![grant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@grant](https://www.ruby-forum.com/u/grant)\
**Post date:** [April 5, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/atom-the-standard-library-rss-module/133918/5 "2008-04-05T14:15:26Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

grant wrote:  
| On 5 Apr, 01:29, Kouhei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

| What I’d like is a consistent interface to the commonly used elements  
| in ATOM and RSS feeds, regardless of version. It must be more  
| difficult than it seems to me, because I’m not aware that anyone does  
| it. I might give it a try just for fun. But, being new to Ruby, I’m  
| not sure where to begin.

You could build upon/look at/submit patches to Simple RSS:  
[http://simple-rss.rubyforge.org/](http://simple-rss.rubyforge.org/)

I’ve used it, and while it is simple to use, it comes at the cost of  
limited functionality (as far as I could see. I only used it to grab  
NetBeans Ruby IDE builds off the web, when the buildserver used updated  
its RSS feed, so take my comments with a grain of salt.)

- – Phillip G.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkf3bSUACgkQbtAgaoJTgL9ijwCfZPylNfWZHsTE02Pec6fQXTcl  
F6EAoJCO3lkfChpIKji9hc52aUaWm9BV  
=Uhvw  
-----END PGP SIGNATURE-----
