Limit an RSS Feed in Ruby -


this seems such simple thing isn't worth question, haven't yet found answer! parsing rss feed using

@rss_industry = rss::parser.parse('http://construction.com/rss/construction.xml', false) 

this brings entire feed. want limit number of items returned. there simple way this?

thanks.

it doesn't that's feature in stdlib rss::parser class.

there other ways parse rss.

but there's no way avoid fetching entire xml file on http, if you're interested in first x items. , you've fetched it, there's no great way avoid parsing entire xml, if want parts of it. there might some complicated way using streaming xml parser, unless xml file really huge, don't want go down there.

instead, if interested in first x items in feed, why not @ those?

 feed = rss::parser.parse('http://construction.com/rss/construction.xml', false)   all_items = feed.items  first_10_items = feed.items.slice(0, 10) 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -