I have the following code
<?php
$xml = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Metallica&api_key=b25b959554ed76058ac220b7b2e0a026");
$artistTag= $xml->artist->children();
$largeImage = $artistTag[7];
echo '<img src="'.$largeImage.'" />';
?>
This will target the 7th node - however the 7th node might not exist so this won't work. Is there anyway to specifically target the large, extralarge or mega nodes?
Example XML
<lfm status="ok">
<artist>
<name>Metallica</name>
<mbid>65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab</mbid>
<url>http://www.last.fm/music/Metallica</url>
<image size="small">
http://img2-ak.lst.fm/i/u/34s/c14fdad46a5c423f86a683501c163c99.png
</image>
<image size="medium">
http://img2-ak.lst.fm/i/u/64s/c14fdad46a5c423f86a683501c163c99.png
</image>
<image size="large">
http://img2-ak.lst.fm/i/u/174s/c14fdad46a5c423f86a683501c163c99.png
</image>
<image size="extralarge">
http://img2-ak.lst.fm/i/u/300x300/c14fdad46a5c423f86a683501c163c99.png
</image>
<image size="mega">
http://img2-ak.lst.fm/i/u/c14fdad46a5c423f86a683501c163c99.png
</image>
<image size="">
http://img2-ak.lst.fm/i/u/arQ/c14fdad46a5c423f86a683501c163c99.png
</image>
So if mega doesn't exist, go for extralarge, if that doesn't exist, go to large etc