Product Advertising API
Getting Started Guide (API Version 2011-08-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Processing Overview

In the previous section, you saw that a Product Advertising API response is an XML document. The elements returned and their values depend on the data stored in Amazon's databases and the response groups specified in the request.

A response group tailors the information returned in a response. For example, the Images response group returns the images of items returned in the response. The TopSellers response group returns the top selling items in a search index. The Product Advertising API Developer Guide lists all of the elements that a response group can potentially return.

The elements returned by a response group are structured. For example, the Item element has several child elements, one of which is Offers, which has a child element, Subtotal, which itself has three child elements: Amount, CurrencyCode, and FormattedPrice, as shown in the following response snippet..

<Item>
  <Offers>
    <Subtotal>
      <Amount>999</Amount>
      <CurrencyCode>US</CurrencyCode>
      <FormattedPrice>$9.99</FormattedPrice>

The parent-to-child succession of structured elements is called an XPath. To parse a result, the Product Advertising API response is turned into an object and then XPaths are used as an efficient means of finding elements and their values.

The following PHP example shows how an XPath is used to display the FormattedPrice value after first making sure there is a value.

if(isset($current->Item->Offers->Subtotal->FormattedPrice)){   print("<br>Price:"
    $current->Offers->Subtotal->FormattedPrice);

The similar expression in C# is:

Label1.Text += "Price: " +
  Item.Offers.Subtotal.FormattedPrice + "<br />"; 

Returning additional values just requires the use of different XPaths.

Typically, responses return more than one item. For that reason, the parsing algorithm must iterate through all of the items returned in a response. For example, in PHP:

foreach($parsed_xml->Items->Item as $current){...}

In C#:

foreach(Item item in response){...}