Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just for comparison, here's some alternate ways to access the nodes using Nokogiri:</p> <pre><code>require 'ap' require 'open-uri' require 'nokogiri' rss = Nokogiri::XML(open('http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml')) # check for parsing errors... puts "Errors exist" if (rss.errors.any?) # use CSS accessors for simplicity... news = rss.search('item').map { |i| # use CSS's namespace wildcard... thumbnail = i.at('media|thumbnail') begin url = thumbnail['url'] rescue url = '' end { 'title' =&gt; i.search('title').text, 'link' =&gt; i.search('link').text, 'description' =&gt; i.search('description').text, 'thumbnail' =&gt; url } } ap [*news[0 .. 1], *news[-2 .. -1]] # &gt;&gt; [ # &gt;&gt; [0] { # &gt;&gt; "title" =&gt; "Royal attack 'not down to radios'", # &gt;&gt; "link" =&gt; "http://www.bbc.co.uk/go/rss/int/news/-/news/uk-11975280", # &gt;&gt; "description" =&gt; "Police deny that a car carrying the Prince of Wales was caught up in student protests because of a breakdown in radio communications.", # &gt;&gt; "thumbnail" =&gt; "http://news.bbcimg.co.uk/media/images/50372000/jpg/_50372715_010819577-1.jpg" # &gt;&gt; }, # &gt;&gt; [1] { # &gt;&gt; "title" =&gt; "Pope Anglican offer 'dented ties'", # &gt;&gt; "link" =&gt; "http://www.bbc.co.uk/go/rss/int/news/-/news/uk-11974543", # &gt;&gt; "description" =&gt; "Britain's ambassador to the Vatican feared a backlash over the Pope's invitation to Anglicans to switch churches, according to leaked US cables.", # &gt;&gt; "thumbnail" =&gt; "http://news.bbcimg.co.uk/media/images/48697000/jpg/_48697938_007958675-1.jpg" # &gt;&gt; }, # &gt;&gt; [2] { # &gt;&gt; "title" =&gt; "Playing defence", # &gt;&gt; "link" =&gt; "http://news.bbc.co.uk/go/rss/int/news/-/1/hi/programmes/from_our_own_correspondent/9275324.stm", # &gt;&gt; "description" =&gt; "The friendly face of township where honeymoon bride was killed", # &gt;&gt; "thumbnail" =&gt; "http://news.bbcimg.co.uk/media/images/50385000/jpg/_50385343_football_afp.jpg" # &gt;&gt; }, # &gt;&gt; [3] { # &gt;&gt; "title" =&gt; "Newspaper review", # &gt;&gt; "link" =&gt; "http://www.bbc.co.uk/go/rss/int/news/-/news/uk-11975338", # &gt;&gt; "description" =&gt; "Papers reflect on attack on royal car", # &gt;&gt; "thumbnail" =&gt; "http://news.bbcimg.co.uk/media/images/49254000/jpg/_49254932_efb006dc-dd09-47bd-8f2d-37752152f772.jpg" # &gt;&gt; } # &gt;&gt; ] </code></pre> <p>Notice the use of the CSS namespace wildcard. It can make your life a lot easier if you don't care about namespaces in the document and want to process everything.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload