Nokogiri extract data from xml

Posted by Awea on Stack Overflow See other posts from Stack Overflow or by Awea
Published on 2011-03-04T10:16:10Z Indexed on 2011/03/07 16:10 UTC
Read the original article Hit count: 176

Filed under:
|
|

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 ?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about ruby-on-rails-3