php check ( if node exists ) in sxml feed
<p>I have a PHP "foreach" script that runs to pull all the uploaded videos <strong>( with related data for each )</strong> from a selected YouTube channel. Then I am able to select the video I wish.
Now I have asked on the youtube forum, but they are reluctant to help outside of thier dedicated api.</p>

<p>So far I have only had this with a single youtube channel, but for my site to work, I need to know that <strong>ALL</strong> channels will work.</p>

<p>Right..... This is the problem.
This is what I get.</p>

<p><em><strong>Warning: main() [function.main]: Node no longer exists in xxxxxxxx.php on line 24
Warning: main() [function.main]: Node no longer exists in xxxxxxxx.php on line 24
Fatal error: Call to a member function attributes() on a non-object in xxxxxxxx.php on line 27</em></strong></p>

<p>/////////////////////   PHP code /////////////////////////</p>

<pre><code> $thumb_count = 1;

 if ($thumb_count &lt;= 50 ){
         $feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $youtube . '/uploads?start-index=1&amp;max-results=50';


// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);

// iterate over entries in feed
foreach ($sxml-&gt;entry as $entry) { 

  // get nodes in media: namespace for media information
  $media = $entry-&gt;children('http://search.yahoo.com/mrss/');

  // get video player URL
  $attrs = $media-&gt;group-&gt;player-&gt;attributes();
  $watch = $attrs['url']; 

  // get video thumbnail
  $attrs = $media-&gt;group-&gt;thumbnail[3]-&gt;attributes();
  $thumbnail = $attrs['url']; 

  // get &lt;yt:duration&gt; node for video length
  $yt = $media-&gt;children('http://gdata.youtube.com/schemas/2007');
  $attrs = $yt-&gt;duration-&gt;attributes();
  $length = $attrs['seconds']; 

  // get &lt;yt:stats&gt; node for viewer statistics
  $yt = $entry-&gt;children('http://gdata.youtube.com/schemas/2007');
  $attrs = $yt-&gt;statistics-&gt;attributes();
  $viewCount = $attrs['viewCount']; 

  // get &lt;gd:rating&gt; node for video ratings
  $gd = $entry-&gt;children('http://schemas.google.com/g/2005'); 
  if ($gd-&gt;rating) {
    $attrs = $gd-&gt;rating-&gt;attributes();
    $rating = $attrs['average']; 
  } else {
    $rating = 0; 
  } 

  $videoID = substr($watch, 31, 11); 
  $vidTitle = $media-&gt;group-&gt;title;
  $channel = $entry-&gt;author-&gt;name;
  $discript = $media-&gt;group-&gt;description;

 $select .= '&lt;table width="150" border="0"&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;div align="center"&gt;&lt;font size="-1" &gt;'.$media-&gt;group-&gt;title.'&lt;/font&gt;&lt;br /&gt;
    &lt;div class="thumbnail"&gt;&lt;a href="xxxxxx?id='.$videoID.'"&gt;
          &lt;img src="'.$thumbnail.'"width="120" height="90" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;hr width="150" color="#FF0000" align="center" size="1" /&gt;';

 ++$thumb_count;
    }

 }
</code></pre>

<p>Now I have tried this <strong>(with my limited knowladge)</strong></p>

<pre><code>// get video player URL
$attrs = $media-&gt;group-&gt;player-&gt;attributes();
if (($attrs =='') || (!$attrs)) { //////no need to double up, but wanted to make sure
continue ;
}
</code></pre>

<p>This then loads my page, but not properly, and still gives an error.</p>

<p>Warning: main() [function.main]: Node no longer exists in xxxxxxxx.php on line 21</p>

<p>Now seeing as I need to go through the foreach loop many times and that there are a few nodes to go through, how can I check, bypass and continue without errors popping up?</p>
