Hi, I am reading from an XML file where the structure of the file is like this:

<item> 
      <title>This is a title</title>  
      <description>Description.</description>  
      <link>Link</link>  
      <media:content width="60" height="50" url="http://www.someurl.com"/>  
      <media:content width="150" height="80" url="http://www.someurl.com"/> 
    </item>  
    <item> 
      <title>This is a title</title>  
      <description>Description.</description>  
      <link>Link</link>  
      <media:content width="60" height="50" url="http://www.someurl.com"/>  
    </item>

I am attempting to access the media:content attributes and have been able to, after some help from veedeoo in another thread. I've since been trying to detect whether <media:content> exists for a specific item at position 1 (2 in the real world) and if it doesn't then get the element at position 0 (1 in the real world). I tried using the following technique to do this:

$xml ='http://feeds.bbci.co.uk/news/england/london/rss.xml';
$xml = @simplexml_load_file($xml); 
 foreach($xml as $items)
{
$item = $items->item;
foreach($item as $news) {
$c_thumb = $news->children('http://search.yahoo.com/mrss/');
/*below is where I've tried to detect the error, I try to see if the element at position 1 and if not then get the element at position 0 instead. but even in the if statement - an error is generated, this is the error:
Fatal error: Call to a member function attributes() on a non-object in <the following line>
*/
if ($c_thumb->thumbnail[1]->attributes() != null) {
$t_attrs = $c_thumb->thumbnail[1]->attributes();
} else {
$t_attrs = $c_thumb->thumbnail[0]->attributes();
}
$thumb = $t_attrs['url'];
echo "<image src='$thumb'></img>";
}
}

Any help?

HElP! Does anyone even know how to fix this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.