simedogz Posted July 20, 2009 Share Posted July 20, 2009 Hello all, I am trying to retrieve the "MediumImage" from this XML document using PHP. How would I do this? I tried using SimpleXML, but I get this error: Notice: Trying to get property of non-object in C:\wamp\www\parsingattempt2.php on line 8 here is my php code: <?php $request_url = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=0XQ36T5736VESGZK91G2&Operation=ItemLookup&ItemId=0679722769&ResponseGroup=ItemAttributes,Offers,Images,Reviews&Version=2009-01-06"; $xml = simplexml_load_file($request_url) or die("feed not loading"); $Book_Image = $xml->MediumImage->URL; echo "$Book_Image"; ?> Attached is the XML file where I am trying to extract the "MediumImage" URL. Note that I have changed it into a txt file to upload it. You should be able just to change the filename to .xml. Thanks for your help. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/166579-getting-php-to-parse-an-xml-document/ Share on other sites More sharing options...
patrickmvi Posted July 20, 2009 Share Posted July 20, 2009 The XML tree doesn't just start at MediumImage, that's most likely your first issue. The full path to the MediumImage node would be Items > Item > MediumImage > URL. Now as far as how you get there using SimpleXML, that could be a little tricky. You may have have to use combinations of array/object type accesses to get to it. SimpleXML is a bit quirky overall but if you figure it out, it works quite well. Link to comment https://forums.phpfreaks.com/topic/166579-getting-php-to-parse-an-xml-document/#findComment-878606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.