Jump to content

foreach loop to parse all records of SimpleXML Element OBJECt


tahir90

Recommended Posts

Iam trying to access amazon API and iam receiving XML perfectly but now I dont know how to traverse all records as in the below example Iam having 3 records but can't travers the xml using foreach Loop

Please help me out and tell me how to use foreach loop ?? :( Its urgent

 

$search="9781439181799,9780393334296,9781605298627";  
	$result = $obj->getItemByUpc($search, "Books");

foreach($result->children() as $key )
{

$data  = $key->Items->Request->ItemLookupRequest->ItemId."<br/ >";
echo $data;
}

 

Moderator Edit: added

 tags[/i][/size]
Link to comment
Share on other sites

this is the response iam getting from amazon for two item ids : 9781441807410,9780765312778 these ids can be upto 10 so that 10 records can be received in one response I would like to fetch Publisher,Author etc from the below response

 

 

SimpleXMLElement Object ( [OperationRequest] => SimpleXMLElement Object ( [RequestId] => 2a3c64bf-a114-4f3d-b056-a2a96517500c [Arguments] => SimpleXMLElement Object ( [Argument] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Service [Value] => AWSECommerceService ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Timestamp [Value] => 2011-04-30T15:44:25Z ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Operation [Value] => ItemLookup ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Version [Value] => 2009-03-31 ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => SearchIndex [Value] => Books ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Signature [Value] => LTBa5YNCEni10WpJAz+bkss3XGWgBrbKivXPYIM3sbQ= ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => ItemId [Value] => 9781441807410,9780765312778 ) ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => IdType [Value] => ISBN ) ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => AWSAccessKeyId [Value] => AKIAJDMPZE2CPBNFJVHA ) ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => ResponseGroup [Value] => ItemAttributes,Offers,SalesRank ) ) ) ) [RequestProcessingTime] => 0.0872430000000000 ) [items] => SimpleXMLElement Object ( [Request] => SimpleXMLElement Object ( [isValid] => True [itemLookupRequest] => SimpleXMLElement Object ( [Condition] => New [DeliveryMethod] => Ship [idType] => ISBN [MerchantId] => Amazon [OfferPage] => 1 [itemId] => Array ( [0] => 9781441807410 [1] => 9780765312778 ) [ResponseGroup] => Array ( [0] => ItemAttributes [1] => Offers [2] => SalesRank ) [ReviewPage] => 1 [ReviewSort] => -SubmissionDate [searchIndex] => Books [VariationPage] => All ) ) [item] => Array ( [0] => SimpleXMLElement Object ( [ASIN] => 1441807411 [DetailPageURL] => http://www.amazon.com/Love-Dare-Stephen-Kendrick-Alex/dp/1441807411%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1441807411 [itemLinks] => SimpleXMLElement Object ( [itemLink] => Array ( [0] => SimpleXMLElement Object ( [Description] => Technical Details => http://www.amazon.com/Love-Dare-Stephen-Kendrick-Alex/dp/tech-data/1441807411%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D1441807411 ) [1] => SimpleXMLElement Object ( [Description] => Add To Baby Registry => http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3D1441807411%26SubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D1441807411 ) [2] => SimpleXMLElement Object ( [Description] => Add To Wedding Registry => http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3D1441807411%26SubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D1441807411 ) [3] => SimpleXMLElement Object ( [Description] => Add To Wishlist => http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3D1441807411%26SubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D1441807411 ) [4] => SimpleXMLElement Object ( [Description] => Tell A Friend => http://www.amazon.com/gp/pdp/taf/1441807411%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D1441807411 ) [5] => SimpleXMLElement Object ( [Description] => All Customer Reviews => http://www.amazon.com/review/product/1441807411%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D1441807411 ) [6] => SimpleXMLElement Object ( [Description] => All Offers => http://www.amazon.com/gp/offer-listing/1441807411%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D1441807411 ) ) ) [salesRank] => 386347 [itemAttributes] => SimpleXMLElement Object ( [Author] => Stephen Kendrick and Alex Kendrick [binding] => Audio CD [Creator] => Nick Archer [DeweyDecimalNumber] => 248 [EAN] => 9781441807410 [Edition] => Unabridged [Feature] => Array ( [0] => ISBN13: 9781441807410 [1] => Condition: USED - Good [2] => Notes: BUY WITH CONFIDENCE, Over one million books sold! 98% Positive feedback. Compare our books, prices and service to the competition. 100% Satisfaction Guaranteed ) [Format] => Array ( [0] => Audiobook [1] => CD [2] => Unabridged ) [iSBN] => 1441807411 [Label] => Brilliance Audio on CD Unabridged [Languages] => SimpleXMLElement Object ( [Language] => Array ( [0] => SimpleXMLElement Object ( [Name] => English [Type] => Unknown ) [1] => SimpleXMLElement Object ( [Name] => English [Type] => Original Language ) [2] => SimpleXMLElement Object ( [Name] => English [Type] => Published ) ) ) [ListPrice] => SimpleXMLElement Object ( [Amount] => 1499 [CurrencyCode] => USD [FormattedPrice] => $14.99 ) [Manufacturer] => Brilliance Audio on CD Unabridged [NumberOfItems] => 4 [PackageDimensions] => SimpleXMLElement Object ( [Height] => 140 [Length] => 710 [Weight] => 4 [Width] => 520 ) [ProductGroup] => Book [ProductTypeName] => ABIS_BOOK [PublicationDate] => 2009-07-15 [Publisher] => Brilliance Audio on CD Unabridged [ReleaseDate] => 2009-07-15 [studio] => Brilliance Audio on CD Unabridged [Title] => The Love Dare ) [OfferSummary] => SimpleXMLElement Object ( [LowestNewPrice] => SimpleXMLElement Object ( [Amount] => 499 [CurrencyCode] => USD [FormattedPrice] => $4.99 ) [LowestUsedPrice] => SimpleXMLElement Object ( [Amount] => 389 [CurrencyCode] => USD [FormattedPrice] => $3.89 ) [TotalNew] => 33 [TotalUsed] => 16 [TotalCollectible] => 0 [TotalRefurbished] => 0 ) [Offers] => SimpleXMLElement Object ( [TotalOffers] => 1 [TotalOfferPages] => 1 [Offer] => SimpleXMLElement Object ( [Merchant] => SimpleXMLElement Object ( [MerchantId] => ATVPDKIKX0DER [GlancePage] => http://www.amazon.com/gp/help/seller/home.html?seller=ATVPDKIKX0DER [AverageFeedbackRating] => 0.0 [TotalFeedback] => 0 ) [OfferAttributes] => SimpleXMLElement Object ( [Condition] => New [subCondition] => new ) [OfferListing] => SimpleXMLElement Object ( [OfferListingId] => rRFbk9WWcoPXIvNBTMxG5gLrTiHAWPID2fYpCoKc82dQRDAiPA%2B2YzZHWrxfjEuhHvMMLKP6laYh5LJAnJUzvTHGhyCcOv3N7QWa7XT%2BC7w%3D [Price] => SimpleXMLElement Object ( [Amount] => 1124 [CurrencyCode] => USD [FormattedPrice] => $11.24 ) [AmountSaved] => SimpleXMLElement Object ( [Amount] => 375 [CurrencyCode] => USD [FormattedPrice] => $3.75 ) [PercentageSaved] => 25 [Availability] => Usually ships in 24 hours [AvailabilityAttributes] => SimpleXMLElement Object ( [AvailabilityType] => now [MinimumHours] => 0 [MaximumHours] => 0 ) [Quantity] => -1 [isEligibleForSuperSaverShipping] => 1 ) ) ) ) [1] => SimpleXMLElement Object ( [ASIN] => 0765312778 [DetailPageURL] => http://www.amazon.com/Aftershock-Others-Oddities-Paul-Wilson/dp/0765312778%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0765312778 [itemLinks] => SimpleXMLElement Object ( [itemLink] => Array ( [0] => SimpleXMLElement Object ( [Description] => Technical Details => http://www.amazon.com/Aftershock-Others-Oddities-Paul-Wilson/dp/tech-data/0765312778%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0765312778 ) [1] => SimpleXMLElement Object ( [Description] => Add To Baby Registry => http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3D0765312778%26SubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0765312778 ) [2] => SimpleXMLElement Object ( [Description] => Add To Wedding Registry => http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3D0765312778%26SubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0765312778 ) [3] => SimpleXMLElement Object ( [Description] => Add To Wishlist => http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3D0765312778%26SubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0765312778 ) [4] => SimpleXMLElement Object ( [Description] => Tell A Friend => http://www.amazon.com/gp/pdp/taf/0765312778%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0765312778 ) [5] => SimpleXMLElement Object ( [Description] => All Customer Reviews => http://www.amazon.com/review/product/0765312778%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0765312778 ) [6] => SimpleXMLElement Object ( [Description] => All Offers => http://www.amazon.com/gp/offer-listing/0765312778%3FSubscriptionId%3DAKIAJDMPZE2CPBNFJVHA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0765312778 ) ) ) [salesRank] => 175379 [itemAttributes] => SimpleXMLElement Object ( [Author] => F. Paul Wilson [binding] => Hardcover [DeweyDecimalNumber] => 813.54 [EAN] => 9780765312778 [Edition] => First Edition [Feature] => Array ( [0] => ISBN13: 9780765312778 [1] => Condition: New [2] => Notes: BRAND NEW FROM PUBLISHER! 100% Satisfaction Guarantee. Tracking provided on most orders. Buy with Confidence! Millions of books sold! ) [iSBN] => 0765312778 [itemDimensions] => SimpleXMLElement Object ( [Height] => 130 [Length] => 952 [Weight] => 128 [Width] => 644 ) [Label] => Forge Books [Languages] => SimpleXMLElement Object ( [Language] => Array ( [0] => SimpleXMLElement Object ( [Name] => English [Type] => Unknown ) [1] => SimpleXMLElement Object ( [Name] => English [Type] => Original Language ) [2] => SimpleXMLElement Object ( [Name] => English [Type] => Published ) ) ) [ListPrice] => SimpleXMLElement Object ( [Amount] => 2595 [CurrencyCode] => USD [FormattedPrice] => $25.95 ) [Manufacturer] => Forge Books [NumberOfItems] => 1 [NumberOfPages] => 352 [PackageDimensions] => SimpleXMLElement Object ( [Height] => 150 [Length] => 940 [Weight] => 125 [Width] => 640 ) [ProductGroup] => Book [ProductTypeName] => ABIS_BOOK [PublicationDate] => 2009-03-31 [Publisher] => Forge Books [ReleaseDate] => 2009-03-31 [studio] => Forge Books [Title] => Aftershock & Others: 19 Oddities ) [OfferSummary] => SimpleXMLElement Object ( [LowestNewPrice] => SimpleXMLElement Object ( [Amount] => 539 [CurrencyCode] => USD [FormattedPrice] => $5.39 ) [LowestUsedPrice] => SimpleXMLElement Object ( [Amount] => 535 [CurrencyCode] => USD [FormattedPrice] => $5.35 ) [LowestCollectiblePrice] => SimpleXMLElement Object ( [Amount] => 1699 [CurrencyCode] => USD [FormattedPrice] => $16.99 ) [TotalNew] => 26 [TotalUsed] => 15 [TotalCollectible] => 5 [TotalRefurbished] => 0 ) [Offers] => SimpleXMLElement Object ( [TotalOffers] => 1 [TotalOfferPages] => 1 [Offer] => SimpleXMLElement Object ( [Merchant] => SimpleXMLElement Object ( [MerchantId] => ATVPDKIKX0DER [GlancePage] => http://www.amazon.com/gp/help/seller/home.html?seller=ATVPDKIKX0DER [AverageFeedbackRating] => 0.0 [TotalFeedback] => 0 ) [OfferAttributes] => SimpleXMLElement Object ( [Condition] => New [subCondition] => new ) [OfferListing] => SimpleXMLElement Object ( [OfferListingId] => %2BW7nbr5R0%2FFCyyeu%2FkWWH1BJo2LNg6AM4vm1aMjsXMexK33h6t2LbTeM54odyyc0C3Yg00lK00kMWd7B4FOXBSL2bww4YZDAJ6w2rFNkOcM%3D [Price] => SimpleXMLElement Object ( [Amount] => 1713 [CurrencyCode] => USD [FormattedPrice] => $17.13 ) [AmountSaved] => SimpleXMLElement Object ( [Amount] => 882 [CurrencyCode] => USD [FormattedPrice] => $8.82 ) [PercentageSaved] => 34 [Availability] => Usually ships in 24 hours [AvailabilityAttributes] => SimpleXMLElement Object ( [AvailabilityType] => now [MinimumHours] => 0 [MaximumHours] => 0 ) [Quantity] => -1 [isEligibleForSuperSaverShipping] => 1 ) ) ) ) ) ) )

 

and now i wanted to parse through it to get the data

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.