Nokogiri XML Attributes reading of some node


<rss>
<channel>
<item>
<enclosure url=”http://www.leonardo-hotels.mobi/octopus/Upload/Images/Resorts/batyam%20deluxe%20livingroom%20255.jpg&#8221; length=”100″ type=”image/jpeg”/>
</item>
</channel>
</rss>

To access tag’s url attribute

root.at_xpath("rss/channel/item").xpath('enclosure').attribute('url')

def read_by_nokogiri(url)
      url, timeout =  url.strip, 60
      uri = URI.parse(URI.encode(url))
      http = Net::HTTP.new(uri.host, uri.port)
      http.open_timeout, http.read_timeout = timeout, timeout
      http.request_get(uri.request_uri) do |response|
      root = Nokogiri::XML(response.read_body)
       puts  root.at_xpath("rss/channel/item").xpath('enclosure').attribute('url')
       puts "---------->>>>>>>>>>>>>>>"
       return root.at_xpath("rss/channel")
      end
end

More help

Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with:
Posted in Nokogiri, XML

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: