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 8643543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:04:25+00:00 2026-06-12T12:04:25+00:00

I am running a php script which calls upon the Amazon MWS API and

  • 0

I am running a php script which calls upon the Amazon MWS API and I am trying to query a book by an isbn number.

I get the following returned

SimpleXMLElement Object
(
    [GetMatchingProductResult] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [ASIN] => 1908256052
                    [status] => Success
                )

            [Product] => SimpleXMLElement Object
                (
                    [Identifiers] => SimpleXMLElement Object
                        (
                            [MarketplaceASIN] => SimpleXMLElement Object
                                (
                                    [MarketplaceId] => A1F83G8C2ARO7P
                                    [ASIN] => 1908256052
                                )

                        )

                    [AttributeSets] => SimpleXMLElement Object
                        (
                        )

                    [Relationships] => SimpleXMLElement Object
                        (
                        )

                    [SalesRankings] => SimpleXMLElement Object
                        (
                            [SalesRank] => Array
                                (
                                    [0] => SimpleXMLElement Object
                                        (
                                            [ProductCategoryId] => book_display_on_website
                                            [Rank] => 3304
                                        )

                                    [1] => SimpleXMLElement Object
                                        (
                                            [ProductCategoryId] => 271146
                                            [Rank] => 11
                                        )

                                    [2] => SimpleXMLElement Object
                                        (
                                            [ProductCategoryId] => 1039764
                                            [Rank] => 25
                                        )

                                    [3] => SimpleXMLElement Object
                                        (
                                            [ProductCategoryId] => 270704
                                            [Rank] => 38
                                        )

                                )

                        )

                )

        )

    [ResponseMetadata] => SimpleXMLElement Object
        (
            [RequestId] => bba76d27-9648-4988-b0b6-63b43116d16d
        )

)

when I should be getting something like…

<?xml version="1.0"?>
<GetMatchingProductResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetMatchingProductResult ASIN="1908256052" status="Success">
  <Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
    <Identifiers>
      <MarketplaceASIN>
        <MarketplaceId>A1F83G8C2ARO7P</MarketplaceId>
        <ASIN>1908256052</ASIN>
      </MarketplaceASIN>
    </Identifiers>
    <AttributeSets>
      <ns2:ItemAttributes xml:lang="en-GB">
        <ns2:Author>Slimming World</ns2:Author>
        <ns2:Binding>Hardcover</ns2:Binding>
        <ns2:Format>Illustrated</ns2:Format>
        <ns2:IsEligibleForTradeIn>true</ns2:IsEligibleForTradeIn>
        <ns2:Label>Slimming World</ns2:Label>
        <ns2:Languages>
          <ns2:Language>
            <ns2:Name>english</ns2:Name>
            <ns2:Type>Unknown</ns2:Type>
          </ns2:Language>
          <ns2:Language>
            <ns2:Name>english</ns2:Name>
            <ns2:Type>Original Language</ns2:Type>
          </ns2:Language>
          <ns2:Language>
            <ns2:Name>english</ns2:Name>
            <ns2:Type>Published</ns2:Type>
          </ns2:Language>
        </ns2:Languages>
        <ns2:ListPrice>
          <ns2:Amount>16.99</ns2:Amount>
          <ns2:CurrencyCode>GBP</ns2:CurrencyCode>
        </ns2:ListPrice>
        <ns2:Manufacturer>Slimming World</ns2:Manufacturer>
        <ns2:NumberOfItems>1</ns2:NumberOfItems>
        <ns2:NumberOfPages>224</ns2:NumberOfPages>
        <ns2:PackageDimensions>
          <ns2:Height Units="inches">0.87</ns2:Height>
          <ns2:Length Units="inches">9.69</ns2:Length>
          <ns2:Width Units="inches">7.64</ns2:Width>
          <ns2:Weight Units="pounds">1.85</ns2:Weight>
        </ns2:PackageDimensions>
        <ns2:ProductGroup>Book</ns2:ProductGroup>
        <ns2:ProductTypeName>ABIS_BOOK</ns2:ProductTypeName>
        <ns2:PublicationDate>2011-11-20</ns2:PublicationDate>
        <ns2:Publisher>Slimming World</ns2:Publisher>
        <ns2:SmallImage>
          <ns2:URL>http://ecx.images-amazon.com/images/I/61aM-pJlQtL._SL75_.jpg</ns2:URL>
          <ns2:Height Units="pixels">75</ns2:Height>
          <ns2:Width Units="pixels">64</ns2:Width>
        </ns2:SmallImage>
        <ns2:Studio>Slimming World</ns2:Studio>
        <ns2:Title>Slimming World Extra Easy All in One</ns2:Title>
      </ns2:ItemAttributes>
    </AttributeSets>
    <Relationships/>
    <SalesRankings>
      <SalesRank>
        <ProductCategoryId>book_display_on_website</ProductCategoryId>
        <Rank>2767</Rank>
      </SalesRank>
      <SalesRank>
        <ProductCategoryId>271146</ProductCategoryId>
        <Rank>7</Rank>
      </SalesRank>
      <SalesRank>
        <ProductCategoryId>1039764</ProductCategoryId>
        <Rank>24</Rank>
      </SalesRank>
      <SalesRank>
        <ProductCategoryId>270704</ProductCategoryId>
        <Rank>38</Rank>
      </SalesRank>
    </SalesRankings>
  </Product>
</GetMatchingProductResult>
<ResponseMetadata>
  <RequestId>e8dd69e8-7a40-4cab-9793-a666c0648753</RequestId>
</ResponseMetadata>
</GetMatchingProductResponse>

The function im using is

public function getXML($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $response = curl_exec($ch);

    return simplexml_load_string($response);
}

Is there something I am missing? why are different results returned?

  • 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-12T12:04:27+00:00Added an answer on June 12, 2026 at 12:04 pm

    The function simplexml_load_string only returns the interpreted XML as a SimpleXMLElement object. Try SimpleXMLElement::asXML instead:

    public function getXML($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        $response = curl_exec($ch);
    
        // return $xml if you still want to parse the data elsewhere
        $xml = simplexml_load_string($response);
    
        // return this if you just want the raw XML string
        return $xml->asXML();
    }
    

    Update: How to parse and iterate over elements…

    SimpleXMLElement objects are iterable and accessible. This means you can use foreach to iterate over an element:

    foreach ($xml->GetMatchingProductResult->Product as $product) {
        // do something for each <Product>, such as output the ASIN...
        echo $product->Identifiers->MarketplaceASIN->ASIN;
    }
    

    You can refer to the PHP documentation on Basic SimpleXML usage for more examples. At some point, you will have to deal with namespaces. Here are some additional resources:

    • Parse XML with Namespace using SimpleXML
    • http://www.sitepoint.com/simplexml-and-namespaces/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a cronjob that calls a php script. I get failed to open
I am running a cron job every five minutes which calls a php script
How do we determine which user the php script is running under when I
I have a long running php script which is basically an infinite loop listening
I'm trying to run a PHP script which has pg_connect($connection_string) and it just crashes
I have a script which calls an external API using curl. This script worked
I am trying to trigger the running of a shell script using PHP. Essentially,
I'm trying to debug a php script that is running on my university's server.
I have a simple bash script which calls a php script every 10 minutes
I am running a php script from the console. I cannot see any cookies

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.