You are here

public function LookupXmlToItemsArray::transform in Amazon Product Advertisement API 8.2

Parameters

string $response: XML response from Amazon's REST services.

Return value

array Array of SimpleXMLElement objects representing the response from Amazon.

File

src/LookupXmlToItemsArray.php, line 36
Contains Drupal\amazon\LookupXmlToItemsArray

Class

LookupXmlToItemsArray

Namespace

Drupal\amazon

Code

public function transform($response) {
  $xml = simplexml_load_string($response);
  $xml
    ->registerXPathNamespace("amazon", "http://webservices.amazon.com/AWSECommerceService/2011-08-01");
  $errors = $xml
    ->xpath('//amazon:Errors');
  foreach ($errors as $error) {
    $error_code = (string) $error->Error->Code;
    $error_message = (string) $error->Error->Message;
    $this
      ->logError($error_code, $error_message);
  }
  $elements = $xml
    ->xpath('//amazon:ItemLookupResponse/amazon:Items/amazon:Item');
  return $elements;
}