Problems parsing Google Data Booksearch API XML in Ruby
- by FrogBot
I'm trying to parse some XML I've gotten from the Google Data Booksearch API and I'm having trouble trying to target a specific element. Currently my code looks like so:
require 'gdata'
client = GData::Client::BookSearch.new
feed = client.get("http://books.google.com/books/feeds/volumes?q=Foundation").to_xml
books = []
feed.elements.each('entry') do |entry|
book = {
:title => entry.elements['title'].text,
:author => entry.elements['dc:creator'].text,
:book_id => entry.elements['dc:identifier'].text
}
books.push(book)
end
p books
and that all works fine, but I want to add a thumbnail URL to the book hash. The tag with each book's thumbnail URL looks like so:
<feed>
<entry>
...
<link rel="http://schemas.google.com/books/2008/thumbnail" type="image/x-unknown" href="http://bks6.books.google.com/books?id=ID5P7xbmcO8C&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_gdata"/>
...
</entry>
</feed>
I want to grab the contents of the href attribute from this element and I'm not exactly sure how. Can anyone help me out here?