Nokogiri extract data from xml
- by Awea
Hi guys, i try to extract data from a xml in rails application with the Nokogiri gem,
the xml :
<item>
<description>
<img src="something" title="anothething">
<p>text, bla bla...</p>
</description>
</item>
Actually i do something like this to extract data from the xml :
def test_content
@return = Array.new
site = 'http://www.les-encens.com/modules/feeder/rss.php?id_category=0'
@doc = Nokogiri::XML(open(site, "UserAgent" => "Ruby-OpenURI"))
@doc.xpath("//item").each do |n|
@return << [
n.xpath('description')
]
end
end
Could you show me how extract just the src attribute from the img tag ?