Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:43:10+00:00 2026-05-20T04:43:10+00:00

Given the hpricot xml at the bottom of this post, how would I select

  • 0

Given the hpricot xml at the bottom of this post, how would I select the “item” without having to use .each? Every single piece of documentation uses a variation of

@res.items.each do |item|
  # do stuff
end

Which is pointless in this case because there is only ever one “item”. Been tearing y hair out for the last ages trying to get this right.

Edited to add more information:

Ok so judging from the early comments, I’m missing the point somewhere so I’ll provide more information.

I’m using a ruby gem called amazon-ecs to retrieve product information from Amazon. On the gem’s site it is described as

A generic Ruby Amazon Product Advertising API (previously known as E-commerce REST API) using Hpricot. It uses Response and Element wrapper classes for easy access to the REST API XML output. It is generic, so you can extend Amazon::Ecs to support the other not-implemented operations easily; and the response object just wraps around Hpricot element object, instead of providing one-to-one object/attributes to XML elements map.

Now to be hones I don’t really understand what that means but I suspect the bit about the wrapping Response object is what’s making this difficult!

Basically, when I do this:

@res = Amazon::Ecs.item_lookup(ean, options_hash)

and then I print out “debug @res”, I get what I have below.

Hope that helps!
End edit

Hpricot xml:

<Amazon::Ecs::Response:0xa4449cc @doc=#<Hpricot::Doc 
{xmldecl "<?xml version=\"1.0\" ?>"} 
{elem <itemlookupresponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05"> 
  {elem <operationrequest> 
    {elem <httpheaders> 
      {emptyelem <header name="UserAgent" value="Ruby">} 
    </HTTPHeaders>} 
    {elem <requestid> "b89bad91-f5a1-4daf-87f2-d309dded35d6" </RequestId>} 
    {elem <arguments> 
      {emptyelem <argument name="Operation" value="ItemLookup">} 
      {emptyelem <argument name="SearchIndex" value="Books">} 
      {emptyelem <argument name="Signature" value="dasdasdsadsadsafdfdsfsdsasadsadsd">} 
      {emptyelem <argument name="ItemId" value="9780307463746">} 
      {emptyelem <argument name="IdType" value="ISBN">} 
      {emptyelem <argument name="AWSAccessKeyId" value="sdasdsadsadsadsadsadd">} 
      {emptyelem <argument name="Timestamp" value="2011-02-17T15:08:09Z">} 
      {emptyelem <argument name="Service" value="AWSECommerceService">} 
    </Arguments>} 
    {elem <requestprocessingtime> "0.0252220000000000" </RequestProcessingTime>} 
  </OperationRequest>} 
  {elem <items> 
    {elem <request> 
      {elem <isvalid> "True" </IsValid>} 
      {elem <itemlookuprequest> 
        {elem <condition> "New" </Condition>} 
        {elem <deliverymethod> "Ship" </DeliveryMethod>} 
        {elem <idtype> "ISBN" </IdType>} 
        {elem <merchantid> "Amazon" </MerchantId>} 
        {elem <offerpage> "1" </OfferPage>} 
        {elem <itemid> "9780307463746" </ItemId>} 
        {elem <responsegroup> "Small" </ResponseGroup>} 
        {elem <reviewpage> "1" </ReviewPage>} 
        {elem <searchindex> "Books" </SearchIndex>} 
      </ItemLookupRequest>} 
    </Request>} 
    {elem <item> 
      {elem <asin> "0307463745" </ASIN>} 
      {elem <detailpageurl> "http://www.amazon.com/Rework-Jason-Fried/dp/0307463745%3FSubscriptionId%3DAKIAIV6GP6CJC3AINUUQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0307463745" </DetailPageURL>} 
      {elem <smallimage> 
        {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL75_.jpg" </URL>} 
        {elem <height units="pixels"> "75" </Height>} 
        {elem <width units="pixels"> "50" </Width>} 
      </SmallImage>} 
      {elem <mediumimage> 
        {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL160_.jpg" </URL>} 
        {elem <height units="pixels"> "160" </Height>} 
        {elem <width units="pixels"> "106" </Width>} 
      </MediumImage>} {elem <largeimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL.jpg" </URL>} {elem <height units="pixels"> "500" </Height>} {elem <width units="pixels"> "331" </Width>} </LargeImage>} {elem <imagesets> {elem <imageset category="primary"> {elem <swatchimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL30_.jpg" </URL>} {elem <height units="pixels"> "30" </Height>} {elem <width units="pixels"> "20" </Width>} </SwatchImage>} {elem <smallimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL75_.jpg" </URL>} {elem <height units="pixels"> "75" </Height>} {elem <width units="pixels"> "50" </Width>} </SmallImage>} {elem <mediumimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL160_.jpg" </URL>} {elem <height units="pixels"> "160" </Height>} {elem <width units="pixels"> "106" </Width>} </MediumImage>} {elem <largeimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL.jpg" </URL>} {elem <height units="pixels"> "500" </Height>} {elem <width units="pixels"> "331" </Width>} </LargeImage>} </ImageSet>} </ImageSets>}
      {elem <itemattributes> 
        {elem <author> "Jason Fried" </Author>} 
        {elem <author> "David Heinemeier Hansson" </Author>} 
        {elem <manufacturer> "Crown Business" </Manufacturer>} 
        {elem <productgroup> "Book" </ProductGroup>} 
        {elem <title> "Rework" </Title>} 
      </ItemAttributes>} 
    </Item>} 
  </Items>} 
</ItemLookupResponse>}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:43:11+00:00Added an answer on May 20, 2026 at 4:43 am

    First, extract the Hpricot object from @res (from the docs).

    doc = @res.doc
    

    Then, you should be able to use the Hpricot object:

    puts (doc/:item).inner_html
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this: $ids = ''; I just realized that this: $single = $ids ==
I am trying to use hpricot in a controller. I would like to pass
Given this xml <Documents> <Section> <SectionName>Green</SectionName> <Document> <FileName>Tier 1 Schedules</FileName> </Document> <Document> <FileName>Tier 3
Given a select with multiple option's in jQuery. $select = $(<select></select>); $select.append(<option>Jason</option>) //Key =
Given an absolute or relative path (in a Unix-like system), I would like to
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given a (source) patch file, what's the easiest way to apply this patch on
Given this HTML: <ul id=topnav> <li id=topnav_galleries><a href=#>Galleries</a></li> <li id=topnav_information><a href=#>Information</a></li> </ul> And this
Given a spreadsheet with two columns, say A and B, each containing n values
Given a table like this: [Last Name] [First Name] [DepartmentID] --------------------------------------- Doe John 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.