-1

I'm using the Amazon api to get product data and I'm receiving this as a SimpleXMLElement Object. I already searched around but I couldn't find a way to echo specific value with php. Here is the code:

The XML output:

<itemlookupresponse
    xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
    <operationrequest>
        <requestid>fd3f07ee-1e2f-4c23-b27b-a06f30d0fc96</requestid>
        <arguments>
            <argument name="AWSAccessKeyId" value="AKIAIXTLBUPZHUI6YHHQ">
                <argument name="AssociateTag" value="gamuni064-21">
                    <argument name="ItemId" value="B00BQ8XVPQ">
                        <argument name="Operation" value="ItemLookup">
                            <argument name="ResponseGroup" value="Medium">
                                <argument name="Service" value="AWSECommerceService">
                                    <argument name="Timestamp" value="2017-12-26T23:28:25Z">
                                        <argument name="Version" value="2009-03-31">
                                            <argument name="Signature" value="fPD72To29HTb5kzYw/ioMF5WgCljZkGXo/o4ywXMric="></argument>
                                        </argument>
                                    </argument>
                                </argument>
                            </argument>
                        </argument>
                    </argument>
                </argument>
            </argument>
        </arguments>
        <requestprocessingtime>0.0121532670000000</requestprocessingtime>
    </operationrequest>
    <items>
        <request>
            <isvalid>True</isvalid>
            <itemlookuprequest>
                <idtype>ASIN</idtype>
                <itemid>B00BQ8XVPQ</itemid>
                <responsegroup>Medium</responsegroup>
                <variationpage>All</variationpage>
            </itemlookuprequest>
        </request>
        <item>
            <asin>B00BQ8XVPQ</asin>
            <detailpageurl>https://www.amazon.de/39-730-68-Manager-Eck-Schreibtisch-Sonoma-Sideboard/dp/B00BQ8XVPQ?SubscriptionId=AKIAIXTLBUPZHUI6YHHQ&amp;tag=gamuni064-21&amp;linkCode=xm2&amp;camp=2025&amp;creative=165953&amp;creativeASIN=B00BQ8XVPQ</detailpageurl>
            <itemlinks>
                <itemlink>
                    <description>Add To Wishlist</description>
                    <url>https://www.amazon.de/gp/registry/wishlist/add-item.html?asin.0=B00BQ8XVPQ&amp;SubscriptionId=AKIAIXTLBUPZHUI6YHHQ&amp;tag=gamuni064-21&amp;linkCode=xm2&amp;camp=2025&amp;creative=12738&amp;creativeASIN=B00BQ8XVPQ</url>
                </itemlink>
                <itemlink>
                    <description>Tell A Friend</description>
                    <url>https://www.amazon.de/gp/pdp/taf/B00BQ8XVPQ?SubscriptionId=AKIAIXTLBUPZHUI6YHHQ&amp;tag=gamuni064-21&amp;linkCode=xm2&amp;camp=2025&amp;creative=12738&amp;creativeASIN=B00BQ8XVPQ</url>
                </itemlink>
                <itemlink>
                    <description>All Customer Reviews</description>
                    <url>https://www.amazon.de/review/product/B00BQ8XVPQ?SubscriptionId=AKIAIXTLBUPZHUI6YHHQ&amp;tag=gamuni064-21&amp;linkCode=xm2&amp;camp=2025&amp;creative=12738&amp;creativeASIN=B00BQ8XVPQ</url>
                </itemlink>
                <itemlink>
                    <description>All Offers</description>
                    <url>https://www.amazon.de/gp/offer-listing/B00BQ8XVPQ?SubscriptionId=AKIAIXTLBUPZHUI6YHHQ&amp;tag=gamuni064-21&amp;linkCode=xm2&amp;camp=2025&amp;creative=12738&amp;creativeASIN=B00BQ8XVPQ</url>
                </itemlink>
            </itemlinks>
            <salesrank>84714</salesrank>
            <smallimage>
                <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L._SL75_.jpg</url>
                <height units="pixels">53</height>
                <width units="pixels">75</width>
            </smallimage>
            <mediumimage>
                <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L._SL160_.jpg</url>
                <height units="pixels">113</height>
                <width units="pixels">160</width>
            </mediumimage>
            <largeimage>
                <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L.jpg</url>
                <height units="pixels">353</height>
                <width units="pixels">500</width>
            </largeimage>
            <imagesets>
                <imageset category="variant">
                    <swatchimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/51UGI4AGZPL._SL30_.jpg</url>
                        <height units="pixels">21</height>
                        <width units="pixels">30</width>
                    </swatchimage>
                    <smallimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/51UGI4AGZPL._SL75_.jpg</url>
                        <height units="pixels">53</height>
                        <width units="pixels">75</width>
                    </smallimage>
                    <thumbnailimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/51UGI4AGZPL._SL75_.jpg</url>
                        <height units="pixels">53</height>
                        <width units="pixels">75</width>
                    </thumbnailimage>
                    <tinyimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/51UGI4AGZPL._SL110_.jpg</url>
                        <height units="pixels">78</height>
                        <width units="pixels">110</width>
                    </tinyimage>
                    <mediumimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/51UGI4AGZPL._SL160_.jpg</url>
                        <height units="pixels">113</height>
                        <width units="pixels">160</width>
                    </mediumimage>
                    <largeimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/51UGI4AGZPL.jpg</url>
                        <height units="pixels">353</height>
                        <width units="pixels">500</width>
                    </largeimage>
                </imageset>
                <imageset category="primary">
                    <swatchimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L._SL30_.jpg</url>
                        <height units="pixels">21</height>
                        <width units="pixels">30</width>
                    </swatchimage>
                    <smallimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L._SL75_.jpg</url>
                        <height units="pixels">53</height>
                        <width units="pixels">75</width>
                    </smallimage>
                    <thumbnailimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L._SL75_.jpg</url>
                        <height units="pixels">53</height>
                        <width units="pixels">75</width>
                    </thumbnailimage>
                    <tinyimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L._SL110_.jpg</url>
                        <height units="pixels">78</height>
                        <width units="pixels">110</width>
                    </tinyimage>
                    <mediumimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L._SL160_.jpg</url>
                        <height units="pixels">113</height>
                        <width units="pixels">160</width>
                    </mediumimage>
                    <largeimage>
                        <url>https://images-eu.ssl-images-amazon.com/images/I/41uHl3jca9L.jpg</url>
                        <height units="pixels">353</height>
                        <width units="pixels">500</width>
                    </largeimage>
                </imageset>
            </imagesets>
            <itemattributes>
                <binding>Haushaltswaren</binding>
                <brand>Stella Trading</brand>
                <color>Braun</color>
                <ean>4038889025636</ean>
                <eanlist>
                    <eanlistelement>4038889025636</eanlistelement>
                </eanlist>
                <feature>Arbeitsplatz bestehend aus Schreibtisch und Sideboard</feature>
                <feature>Maße B/H/T: Schreibtisch ca. 140x76x65 cm / Sideboard ca. 130x62x40 cm</feature>
                <feature>Korpus: Eiche Sonoma, Front: Weiß</feature>
                <feature>abwischbare Oberflächen</feature>
                <feature>beidseitig montierbar</feature>
                <itemdimensions>
                    <weight units="Hundertstel Pfund">14771</weight>
                </itemdimensions>
                <label>BEGA</label>
                <listprice>
                    <amount>18075</amount>
                    <currencycode>EUR</currencycode>
                    <formattedprice>EUR 180,75</formattedprice>
                </listprice>
                <manufacturer>BEGA</manufacturer>
                <model>39-730-68</model>
                <mpn>39-730-68</mpn>
                <packagedimensions>
                    <height units="hundredths-inches">906</height>
                    <length units="hundredths-inches">5787</length>
                    <weight units="Hundertstel Pfund">14330</weight>
                    <width units="hundredths-inches">2677</width>
                </packagedimensions>
                <packagequantity>1</packagequantity>
                <partnumber>39-730-68</partnumber>
                <productgroup>Furniture</productgroup>
                <producttypename>HOME_FURNITURE_AND_DECOR</producttypename>
                <publisher>BEGA</publisher>
                <studio>BEGA</studio>
                <title>BEGA 39-730-68 Manager Eck-Schreibtisch, Eiche Sonoma Dekor, Tisch 140 x 76 x 65 cm, Sideboard 130 x 62 x 40 cm</title>
            </itemattributes>
            <offersummary>
                <lowestnewprice>
                    <amount>17699</amount>
                    <currencycode>EUR</currencycode>
                    <formattedprice>EUR 176,99</formattedprice>
                </lowestnewprice>
                <totalnew>5</totalnew>
                <totalused>0</totalused>
                <totalcollectible>0</totalcollectible>
                <totalrefurbished>0</totalrefurbished>
            </offersummary>
            <editorialreviews>
                <editorialreview>
                    <source>Product Description
                        <content>Schreibtisch Bürotisch Büro Winkelkombination Manager Eiche sägerau Dekor / weiss.Praktisch, günstig und moderner Schreibtisch Manager zum Wahnsinnspreis in nagelneuer Farbe Eiche Sägerau mit Applikationen in weiss. 



Die komplette Kombination inkl. Anstellregal zur Winkelkombination. 

Die Metallbeschläge sorgen für die notwendige Stabilität. 



Angebot Ohne Dekoration, ohne Geräte!</content>
                        <islinksuppressed>0</islinksuppressed>
                    </editorialreview>
                </editorialreviews>
            </item>
        </items>
    </itemlookupresponse>

Note: Don't get confused the text is in German not in Englisch

Now I'm looking for a way to get for example to get the price [ListPrice]([FormattedPrice] =&gt; EUR 180,75) I tried this post but I just don't get any values displayed....

OK, the XML File: https://drive.google.com/open?id=1wIj7S1pTzGkvr70whmDtPYocBV0SjTQ8


Cut-down example

<itemlookupresponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
  <items>
    <item>
      <itemattributes>
        <listprice>
          <amount>18075</amount>
          <currencycode>EUR</currencycode>
          <formattedprice>EUR 180,75</formattedprice>
        </listprice>
      </itemattributes>
    </item>
  </items>
</itemlookupresponse>
Phil
  • 157,677
  • 23
  • 242
  • 245
Game Unity
  • 125
  • 10
  • It's very hard to decipher that variable dump. You'd be better off showing an example of the XML. A cut down version with just the parts you want to display would be preferable. Also, you haven't indicated what you've tried and how / why it isn't working – Phil Dec 26 '17 at 22:56
  • Ok I will edit my question – Game Unity Dec 26 '17 at 23:03
  • Again, variable dumps of complex objects are not very useful. **Show the XML**. Also, **what have you tried?** – Phil Dec 26 '17 at 23:10
  • Sry but this just the way how my function receives the data from Amazon (There is no XML file) I can send you the page where I got the code but it's in German http://www.webcrab.de/blog/produkte-inserieren-mit-amazon-api-und-php.html – Game Unity Dec 26 '17 at 23:18
  • Look, it's impossible to help you without seeing the underlying XML structure, particularly around which elements are part of a collection. Have you at least tried `echo $result->Items->Item->ItemAttributes->ListPrice->FormattedPrice;`? – Phil Dec 26 '17 at 23:19
  • To easily see the XML, use `echo $result->asXML();` – Phil Dec 26 '17 at 23:21
  • Isn't there a way to translate this to a php array? – Game Unity Dec 26 '17 at 23:26
  • I'm not sure what you're asking. `SimpleXMLElement` hides a lot of the details around element collections. That's why it's always best to see the source data as XML – Phil Dec 26 '17 at 23:30
  • Sry for being stupid - I really have no idea about this stuff it's completely new to me. – Game Unity Dec 26 '17 at 23:37
  • Your XML seems malformed. There's no closing `` tag – Phil Dec 26 '17 at 23:53

1 Answers1

1

Can't help but notice all the element names are lowercase yet you seem to be after Items (with a capital "I").

This works fine for me

echo $result->items->item->itemattributes->listprice->formattedprice;

Demo ~ https://eval.in/925698

Phil
  • 157,677
  • 23
  • 242
  • 245
  • I tested this with the full XML file but it dosn't work. – Game Unity Dec 27 '17 at 00:15
  • @GameUnity did you see my comment about the XML being malformed? – Phil Dec 27 '17 at 00:15
  • Oh, but how should I change this... This how I get the data from Amazon – Game Unity Dec 27 '17 at 00:22
  • @GameUnity I don't think you understand. Your XML has an opening `` tag but **no closing ``** tag. It has nothing to do with the `` – Phil Dec 27 '17 at 00:25
  • Or isn't there maybe a way to translate this to a PHP string and just search in the string for the price? I mean if even the data is corrupted... – Game Unity Dec 27 '17 at 00:32
  • I don't think it is corrupted given that your original `print_r($result->Items)` seemed to produce something. I don't know where you got the XML from but I suggest you go back to whatever you originally had and output the XML with `echo $result->asXML();` – Phil Dec 27 '17 at 00:35
  • I was trying to fix this missing closing tag with `str_replace` but hade no luck – Game Unity Dec 27 '17 at 20:47