I wrote a function to pull the ProductGroup from Amazon Web SErvices but I'm getting back the whole object.

function amazon($Access_Key,$Item_Id="B000VCKK02"){
        $allparameter =             

                                "Service"            ."=".  "AWSECommerceService" ."&".
                                "AWSAccessKeyId"  ."=".        $Access_Key        ."&".
                               "Operation"           ."=".   "ItemLookup"         ."&".  
                                "IdType"             ."-".   "ASIN"                ."&".
                               "ItemId"            ."=".   $Item_Id                ."&".
                               "Version"            ."=". "2009-01-06"               
                          ;             

 $request = file_get_contents("http://free.apisigning.com/onca/xml?".$allparameter);
 $parsed_xml = simplexml_load_string($request);		
  //  $parsed_xml['OperationRequest']->Items->Item->ItemAttributes->ProductGroup; 
    $parsed_xml->Items->Item->ItemAttributes->ProductGroup;     
return $parsed_xml;
}

This is one object only. I passed in one ASIN (product number)
I guess I need an XML Editor to read the XML?
As far as I can tell it should be OperationRequest->Items->ItemAttributes->ProductGroup but nothing works.
I just need the PRoductGroup that is all.
See at the very bottom it says ProductGroup "Kitchen" that is all I need in a variable.
Thanks,

object(SimpleXMLElement)#1 (2) { ["OperationRequest"]=> object(SimpleXMLElement)#3 (3) { ["RequestId"]=> string(36) "0b149634-f02f-41a3-9f48-121e554b2884" ["Arguments"]=> object(SimpleXMLElement)#2 (1) { ["Argument"]=> array(8) { [0]=> object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(2) { ["Name"]=> string(9) "Operation" ["Value"]=> string(10) "ItemLookup" } } [1]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(2) { ["Name"]=> string(7) "Service" ["Value"]=> string(19) "AWSECommerceService" } } [2]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(2) { ["Name"]=> string(9) "Signature" ["Value"]=> string(44) "aHFTUdNDr0l8uwQfe+VuHMeFuD1JKwUgM9LrCqf4fLY=" } } [3]=> object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(2) { ["Name"]=> string(7) "Version" ["Value"]=> string(10) "2009-01-06" } } [4]=> object(SimpleXMLElement)#9 (1) { ["@attributes"]=> array(2) { ["Name"]=> string(6) "ItemId" ["Value"]=> string(10) "B000VCKK02" } } [5]=> object(SimpleXMLElement)#10 (1) { ["@attributes"]=> array(1) { ["Name"]=> string(11) "IdType-ASIN" } } [6]=> object(SimpleXMLElement)#11 (1) { ["@attributes"]=> array(2) { ["Name"]=> string(14) "AWSAccessKeyId" ["Value"]=> string(20) "BLIJJJJLLLLIEOAKKLLLIIN" } } [7]=> object(SimpleXMLElement)#12 (1) { ["@attributes"]=> array(2) { ["Name"]=> string(9) "Timestamp" ["Value"]=> string(20) "2010-04-29T02:09:10Z" } } } } ["RequestProcessingTime"]=> string(18) "0.0194620000000000" } ["Items"]=> object(SimpleXMLElement)#4 (2) { ["Request"]=> object(SimpleXMLElement)#13 (2) { ["IsValid"]=> string(4) "True" ["ItemLookupRequest"]=> object(SimpleXMLElement)#15 (10) { ["Condition"]=> string(3) "New" ["DeliveryMethod"]=> string(4) "Ship" ["IdType"]=> string(4) "ASIN" ["MerchantId"]=> string(6) "Amazon" ["OfferPage"]=> string(1) "1" ["ItemId"]=> string(10) "B000VCKK02" ["ResponseGroup"]=> string(5) "Small" ["ReviewPage"]=> string(1) "1" ["ReviewSort"]=> string(15) "-SubmissionDate" ["VariationPage"]=> string(3) "All" } } ["Item"]=> object(SimpleXMLElement)#14 (4) { ["ASIN"]=> string(10) "B000VCKK02" ["DetailPageURL"]=> string(201) "http://www.amazon.com/HoMedics-Professional-Doctors-Scale/dp/B000VCKK02%3FSubscriptionId%3DBLIJJJJLLLLIEOAKKLLLIIN%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000VCKK02" ["ItemLinks"]=> object(SimpleXMLElement)#16 (1) { ["ItemLink"]=> array(7) { [0]=> object(SimpleXMLElement)#18 (2) { ["Description"]=> string(17) "Technical Details" ["URL"]=> string(211) "http://www.amazon.com/HoMedics-Professional-Doctors-Scale/dp/tech-data/B000VCKK02%3FSubscriptionId%3DBLIJJJJLLLLIEOAKKLLLIIN%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000VCKK02" } [1]=> object(SimpleXMLElement)#19 (2) { ["Description"]=> string(20) "Add To Baby Registry" ["URL"]=> string(204) "http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3DB000VCKK02%26SubscriptionId%3DBLIJJJJLLLLIEOAKKLLLIIN%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000VCKK02" } [2]=> object(SimpleXMLElement)#20 (2) { ["Description"]=> string(23) "Add To Wedding Registry" ["URL"]=> string(207) "http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3DB000VCKK02%26SubscriptionId%3DBLIJJJJLLLLIEOAKKLLLIIN%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000VCKK02" } [3]=> object(SimpleXMLElement)#21 (2) { ["Description"]=> string(15) "Add To Wishlist" ["URL"]=> string(208) "http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3DB000VCKK02%26SubscriptionId%3DBLIJJJJLLLLIEOAKKLLLIIN%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000VCKK02" } [4]=> object(SimpleXMLElement)#22 (2) { ["Description"]=> string(13) "Tell A Friend" ["URL"]=> string(173) "http://www.amazon.com/gp/pdp/taf/B000VCKK02%3FSubscriptionId%3DBLIJJJJLLLLIEOAKKLLLIIN%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000VCKK02" } [5]=> object(SimpleXMLElement)#23 (2) { ["Description"]=> string(20) "All Customer Reviews" ["URL"]=> string(177) "http://www.amazon.com/review/product/B000VCKK02%3FSubscriptionId%3DBLIJJJJLLLLIEOAKKLLLIIN%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000VCKK02" } [6]=> object(SimpleXMLElement)#24 (2) { ["Description"]=> string(10) "All Offers" ["URL"]=> string(179) "http://www.amazon.com/gp/offer-listing/B000VCKK02%3FSubscriptionId%3DBLIJJJJLLLLIEOAKKLLLIIN%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000VCKK02" } } } ["ItemAttributes"]=> object(SimpleXMLElement)#17 (3) { ["Manufacturer"]=> string(8) "Homedics" ["ProductGroup"]=> string(7) "Kitchen" ["Title"]=> string(26) "Professional Doctors Scale" } } } }

    It's returning the entire XML object because you told it to:

    return $parsed_xml;  

    Note that this line does absolutely nothing:

    $parsed_xml->Items->Item->ItemAttributes->ProductGroup;      

    and could simply be omitted.

    Now, if you actually wanted to return that ProductGroup node, then [man]return[/man] it instead of returning $parsed_xml (the entire XML object).

      I tried this instead of $parsed_xml.....
      return $parsed_xml['OperationRequest']->Items->Item->ItemAttributes->ProductGroup;
      and I got an error

      Notice: Trying to get property of non-object in /Library/WebServer/Documents/lexsource7.php on line 21

      Notice: Trying to get property of non-object in /Library/WebServer/Documents/lexsource7.php on line 21

      Notice: Trying to get property of non-object in /Library/WebServer/Documents/lexsource7.php on line 21

      Notice: Trying to get property of non-object in /Library/WebServer/Documents/lexsource7.php on line 21

      Notice: Trying to get property of non-object in /Library/WebServer/Documents/lexsource7.php on line 23

      Notice: Trying to get property of non-object in /Library/WebServer/Documents/lexsource7.php on line 23

      Notice: Trying to get property of non-object in /Library/WebServer/Documents/lexsource7.php on line 23

      Notice: Trying to get property of non-object in /Library/WebServer/Documents/lexsource7.php on line 23
      NULL

      And I also tried....
      return $parsed_xml['OperationRequest']['ProductGroup'] ;
      And this time I only got the same error 4 times with the null.

      I also tried....
      return $request['OperationRequest']['ProductGroup'] ;
      and got a fatal error.

        Did you try your original code:

        $parsed_xml->Items->Item->ItemAttributes->ProductGroup; 

        ? Looks right to me.

          Well I did and I get back the entire object not just the ProductGroup.
          I think it is simpleXML_load_string that does that.
          SO I tried it without simplexml_load_string and I get the error
          trying to get a property out of a non-object

            jrough wrote:

            Well I did and I get back the entire object not just the ProductGroup.

            Nothing you posted says you ever tried that yet (and by 'that', I mean returning the line above - not just throwing it on a line of its own as you did in your original post).

            jrough wrote:

            I think it is simpleXML_load_string that does that.

            Well yes, of course it's doing that - it's supposed to. The function takes a string and returns a SimpleXML object containing all of the XML code.

            jrough wrote:

            SO I tried it without simplexml_load_string and I get the error

            Wait.. you removed the function that actually loads the data and creates an object, and you're wondering why you got errors about using a non-object?

              I apologize if it isn't clear, but instead of the whole xml response with all the items I just want the ProductGroup. HOw do I get that one node instead of the whole object. So this line gets the whole object not just the one node in the object?
              $parsed_xml->Items->Item->ItemAttributes->ProductGroup;
              It looks like it should get the PRoductGroup but it does not.

                jrough wrote:

                So this line gets the whole object not just the one node in the object?
                $parsed_xml->Items->Item->ItemAttributes->ProductGroup;

                That line should refer to that node, yes, but that line doesn't actually do anything with it.

                Try adding [man]return[/man] in front of it so that you actually do something. The code you have is analogous to doing something like:

                1+1;
                2*3;
                5;
                "a";

                Those are all valid statements, but without return() or echo()'ing them, you don't actually do anything.

                  thanks, you just made my day !

                    Write a Reply...