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

  • SEARCH
  • Home
  • 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 8658053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:40:22+00:00 2026-06-12T15:40:22+00:00

I am trying and trying to parse an XML document. I can get all

  • 0

I am trying and trying to parse an XML document. I can get all of the information when I look at a var_dump, but what I need to do is pull out the Id and image url from the document. I have tried using a for each loop, and it will go through the loop the correct number of times, but the Id number that I need never changes.
The XML document is:

<?xml version="1.0"?>
<GetMatchingProductForIdResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetMatchingProductForIdResult Id="9781124028491" IdType="ISBN" status="ClientError">
 <Error>
<Type>Sender</Type>
<Code>InvalidParameterValue</Code>
<Message>Invalid ISBN identifier 9781124028491 for marketplace ATVPDKIKX0DER</Message>
</Error>
</GetMatchingProductForIdResult>
<GetMatchingProductForIdResult Id="9780030114687" IdType="ISBN" status="Success">
<Products xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Product>
  <Identifiers>
    <MarketplaceASIN>
      <MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
      <ASIN>0030114683</ASIN>
    </MarketplaceASIN>
  </Identifiers>
  <AttributeSets>
    <ns2:ItemAttributes xml:lang="en-US">
      <ns2:Author>Turk, Jonathan.</ns2:Author>
      <ns2:Binding>Unknown Binding</ns2:Binding>
      <ns2:Label>Saunders College Publishers, USA</ns2:Label>
      <ns2:Manufacturer>Saunders College Publishers, USA</ns2:Manufacturer>
      <ns2:ProductGroup>Book</ns2:ProductGroup>
      <ns2:ProductTypeName>BOOKS_1973_AND_LATER</ns2:ProductTypeName>
      <ns2:PublicationDate>2004-12-07</ns2:PublicationDate>
      <ns2:Publisher>Saunders College Publishers, USA</ns2:Publisher>
      <ns2:SmallImage>
        <ns2:URL>http://g-ecx.images-amazon.com/images/G/01/x-site/icons/no-img-sm._V192198896_.gif</ns2:URL>
        <ns2:Height Units="pixels">40</ns2:Height>
        <ns2:Width Units="pixels">60</ns2:Width>
      </ns2:SmallImage>
      <ns2:Studio>Saunders College Publishers, USA</ns2:Studio>
      <ns2:Title>Introduction to Environmental Studies.</ns2:Title>
    </ns2:ItemAttributes>
  </AttributeSets>
  <Relationships/>
  <SalesRankings/>
</Product>

I have cut it down for brevity.
My php is this:

 foreach($parsed_xml->GetMatchingProductForIdResult as $item ) {
 //$ean =$parsed_xml->GetMatchingProductForIdResult->attributes()->Id; var_dump($ean);//->attributes()->Id
 $current = $parsed_xml->GetMatchingProductForIdResult->Products;

        print_r(" passed the foreach statement ");

 //$status = $parsed_xml->GetMatchingProductForIdResult->attributes()->status;

     //$isbn13 = $ean;print_r($isbn13);
      if(isset($parsed_xml->GetMatchingProductForIdResult, $current, $current->Product, $current->Product->AttributeSets)){
        $amazonResult = array(
                            'isbn' => $parsed_xml->GetMatchingProductForIdResult->attributes()->Id,//$isbn13,
            'ImageURL' => str_replace('SL75','SL200',$current->Product->AttributeSets->children('ns2', true)->ItemAttributes->SmallImage->URL),
                            );
   print_r(" Success was true ");

     }  else {

$amazonResult = array(
                            'isbn' => $parsed_xml->GetMatchingProductForIdResult->attributes()->Id,//$isbn13,
            'ImageURL' => "Jim",
                            );
    print_r(" Success was false ");
}    
    //update image in images table
    print_r(" at the insert statement ");
$conn->query("INSERT INTO images (isbn, image) VALUES ('" . $amazonResult['isbn'] . "', '" . $amazonResult['ImageURL'] . "')");

How do I get each individual Id when going through the loop?

  • 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-06-12T15:40:23+00:00Added an answer on June 12, 2026 at 3:40 pm

    The final solution after much trial and error is:

        $parsed_xml = ProductId_xml($isbn);
    
    
      foreach($parsed_xml->GetMatchingProductForIdResult as $item ) {
     $ean =$item->attributes()->Id;
    $current = $item->Products;
    
     $status = $item->attributes()->status;
    
          if (stristr($status, "Success") == true)
    {
            $amazonResult = array(
                                'isbn' => $ean,//$parsed_xml->GetMatchingProductForIdResult->attributes()->Id,
                'ImageURL' => str_replace('SL75','SL200',$current->Product->AttributeSets->children('ns2', true)->ItemAttributes->SmallImage->URL),
                                );
    
         }  else {
    
    $amazonResult = array(
                                'isbn' => $ean,
                'ImageURL' => "",
                                );
    

    }

    I needed to use $item after the foreach statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse the xml document returned from this link but I get
I am trying to parse a document that is formatted similar to Xml (but
I am trying to parse XML with jsoup, but I can't find any examples
I have this code, but can't get it all working. I am trying to
So I'm trying to parse the following XML document with C#, using System.XML: <root
I'm trying to parse and load an XML document, however I'm getting this exception
Trying to do a simple parse of an XML document. What's the easiest way
Trying to parse some XML but apparently this is too much for a lazy
I am trying to parse an XMl document that i received into a string
I'm trying to parse a simple xml document using a DOM parser in JS,

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.