1

I am trying to get the Washington Post Politics RSS feed to display in my Rails app.

wp_url = 'http://feeds.washingtonpost.com/rss/politics'
open(wp_url) do |rss|
  @wp_feed = RSS::Parser.parse(rss)
end

With that code, I am getting the error:

attribute <url> is missing in tag <source>

What am I doing wrong?

1 Answer 1

5

This error occurs when the external feed is invalid.
In this case, the RSS does not contain the required url attribute for the <source> element.

According to the RSS 2.0 specs for the <source> element,

<source> is an optional sub-element of <item>.

Its value is the name of the RSS channel that the item came from, derived from its . It has one required attribute, url, which links to the XMLization of the source.

<source url="http://www.tomalak.org/links2.xml">Tomalak's Realm</source>

The purpose of this element is to propagate credit for links, to publicize the sources of news items. It can be used in the Post command of an aggregator. It should be generated automatically when forwarding an item from an aggregator to a weblog authoring tool.

The RSS class as mentioned in Ruby 1.9.3 doc explains its parse method with these default parameters:

parse(rss, do_validate=true, ignore_unknown_element=true, parser_class=default_parser)

So if you want to ignore such validation errors, pass false as the second parameter and you'll be reading external RSS feeds with this:

require 'rss'
wp_url = open('http://feeds.washingtonpost.com/rss/politics').read
@wp_rss = RSS::Parser.parse(wp_url, false)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.