tags:

views:

137

answers:

0

Hello,

i have a xml structure of the following form to be parsed using PHP simplexml.

<books>

<book>
<title>XYZ</title>
<author> someone </author>
<images>
<image type="poster" url="<url>" size="cover" id="12345"/>
<image type="poster" url="<url>" size="thumb" id="12345"/>
</images>
</book>

<book>
<title>PQR</title>
<author> someoneelse </author>
<images>
<image type="poster" url="<url>" size="cover" id="67890"/>
<image type="poster" url="<url>" size="thumb" id="67890"/>
</images>
</book>

</books>

Suppose i want to print the first image url of the first book. I am able to do that using

$books = $xml->books; 
$book = $books->book[0]; //Get the first book
$images = $book->images;
print $images->image[0]->attributes()->url ; //This works

But,when i try to print all the image urls for this book it does not work. The code im using is:

$books = $xml->books; 
$book = $books->book[0]; //Get the first book
$images=$book->images;

foreach($images as $image) //This does not work
{
   print $image->attributes()->url;
}

Any way to fix this problem ?

Thank You