I have the following XML:
-
Title 1
http://www.example.com/url-1
Replace this:
@links = doc.xpath('//links/item').map do |i|
{'title' => i.xpath('//title'), 'url' => i.xpath('//url')}
with:
@links = doc.xpath('//links/item').map do |i|
{'title' => i.xpath('title'), 'url' => i.xpath('url')}
Explanation:
//title
and
//url
are absolute XPath expressions and they select all (respectively) title
and all url
elements in the XML document.
Contrast this with:
title
and
url
These are relative XPath expressions and select all (respectively) title
and url
children of the current node only.