Hi.
I'd like 😉 to manage to get data
from YouTube Data API.
xml:

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gml='http://www.opengis.net/gml' xmlns:georss='http://www.georss.org/georss' xmlns:media='http://search.yahoo.com/mrss/' xmlns:yt='http://gdata.youtube.com/schemas/2007' xmlns:gd='http://schemas.google.com/g/2005'>
<id>http://gdata.youtube.com/feeds/api/videos?start-index=20&amp;max-results=1&amp;vq=funny+dogs</id>
<updated>2008-03-10T17:10:48.946Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<title type='text'>YouTube Videos matching query: funny dogs</title>
<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
<link rel='alternate' type='text/html' href='http://www.youtube.com'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos'/>
<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?start-index=20&amp;max-results=1&amp;vq=funny+dogs'/>
<link rel='previous' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?start-index=19&amp;max-results=1&amp;vq=funny+dogs'/>
<link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?start-index=21&amp;max-results=1&amp;vq=funny+dogs'/>
<author>
<name>YouTube</name>
<uri>http://www.youtube.com/</uri>
</author>
<generator version='beta' uri='http://gdata.youtube.com/'>YouTube data API</generator>
<openSearch:totalResults>71511</openSearch:totalResults>
<openSearch:startIndex>20</openSearch:startIndex>
<openSearch:itemsPerPage>1</openSearch:itemsPerPage>
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/haD8RGdX2U0</id>
<published>2007-01-15T02:56:08.000-08:00</published>
<updated>2008-03-09T10:12:11.000-07:00</updated>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Puppies'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Pets'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Dogs'/>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Funny'/>
<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Comedy' label='Comedy'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Animals'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Cute'/>
<title type='text'>FUNNY DOGS 6</title>
<content type='text'>FUNNY DOGS 6 - more of the funniest pet pics on YouTube.   Enjoy!</content>
<link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=haD8RGdX2U0'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/haD8RGdX2U0/related'/>
<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/haD8RGdX2U0'/>
<author>
<name>postingmyvids</name>
<uri>http://gdata.youtube.com/feeds/api/users/postingmyvids</uri>
</author>
<media:group>
<media:title type='plain'>FUNNY DOGS 6</media:title>
<media:description type='plain'>FUNNY DOGS 6 - more of the funniest pet pics on YouTube.   Enjoy!</media:description>
<media:keywords>Animals, Cute, Dogs, Funny, Pets, Puppies</media:keywords>
<yt:duration seconds='105'/>
<media:category label='Comedy' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Comedy</media:category>
<media:content url='rtsp://rtsp2.youtube.com/ChoLENy73wIaEQlN2VdnRPyghRMYDSANFEgGDA==/0/0/0/video.3gp' type='video/3gpp' medium='video' isDefault='true' expression='full' duration='105' yt:format='1'/>
<media:content url='rtsp://rtsp2.youtube.com/ChoLENy73wIaEQlN2VdnRPyghRMYESARFEgGDA==/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='105' yt:format='6'/>
<media:player url='http://www.youtube.com/watch?v=haD8RGdX2U0'/>
<media:thumbnail url='http://img.youtube.com/vi/haD8RGdX2U0/2.jpg' height='97' width='130' time='00:00:52.500'/>
<media:thumbnail url='http://img.youtube.com/vi/haD8RGdX2U0/1.jpg' height='97' width='130' time='00:00:26.250'/>
<media:thumbnail url='http://img.youtube.com/vi/haD8RGdX2U0/3.jpg' height='97' width='130' time='00:01:18.750'/>
<media:thumbnail url='http://img.youtube.com/vi/haD8RGdX2U0/0.jpg' height='240' width='320' time='00:00:52.500'/>
</media:group>
<yt:statistics viewCount='358810'/>
<yt:noembed/>
<gd:rating min='1' max='5' numRaters='363' average='3.80'/>
</entry>
</feed>

I tried with:

$doc = new DOMDocument();
$doc->load('http://gdata.youtube.com/feeds/api/videos?vq=funny+dogs&start-index=20&max-results=1');
//$uri = $doc->documentElement->lookupnamespaceURI('media');
//var_dump($uri);
$xp = new domxpath($doc);
$xp->registerNamespace('media','http://search.yahoo.com/mrss');
$totalResults = $xp->query('/def:feed/def:entry/media:group');
var_dump($totalResults->item(0));

I'm using Visual XPath

but it doesn't work 🙁

Can you help me, please ?

Bye

    I've tried also with :

    $doc = new DOMDocument();
    $doc->load('http://gdata.youtube.com/feeds/api/videos?vq=funny+dogs&start-index=20&max-results=1');
    $title= $doc->getElementsByTagNameNS('http://search.yahoo.com/mrss','title');
    var_dump($title->item(0));
    

    but it doesn't work yet.

    But this works

    $doc = new DOMDocument(); 
    $doc->load('http://gdata.youtube.com/feeds/api/videos?vq=funny+dogs&start-index=20&max-results=1'); 
    $p= $doc->getElementsByTagNameNS('http://a9.com/-/spec/opensearchrss/1.0/', 'totalResults');
    var_dump($p->item(0)->nodeValue);
    

    I don't understand what's the trouble ???????????? 🙁(

      Where is this namespace "def" coming from? In your XML none of your namespaces are called "def". I think you forgot to register it:

      $xp->registerNamespace('def','http://www.w3.org/2005/Atom');
      

      And since 'media' is already declared in the XML document, it's already registered.

        Thanks just a lot buddy.
        😃 😃 😃

        $doc = new DOMDocument(); 
        $doc->load('http://gdata.youtube.com/feeds/api/videos?vq=funny+dogs&start-index=20&max-results=1'); 
        //$uri = $doc->documentElement->lookupnamespaceURI('media'); 
        //var_dump($uri); 
        $xp = new domxpath($doc); 
        $xp->registerNamespace('def','http://www.w3.org/2005/Atom');
        $totalResults = $xp->query('/def:feed/def:entry/media:group'); 
        var_dump($totalResults->item(0)->nodeValue);
        

        I'm trying to get all the data then
        if I succeed in it I'll put resolved to this thread.

        I'm not very sure yet 😉

        Bye.

          $doc = new DOMDocument(); 
          $doc->load('http://gdata.youtube.com/feeds/api/videos?vq=funny+dogs&start-index=20&max-results=3'); 
          $xp = new domxpath($doc); 
          $xp->registerNamespace('def','http://www.w3.org/2005/Atom');
          $groups = $xp->query('/def:feed/def:entry/media:group');
          $search= array(); 
          for ( $i = 0,$len = $groups->length; $i < $len; $i++ ) {
          	$titles = $groups->item($i)->getElementsByTagName("title");
          	foreach($titles as $title){
          		$search['title'][$i][]=$title->firstChild->nodeValue;
          	}
          	$descriptions = $groups->item($i)->getElementsByTagName("description");
          	foreach($descriptions as $description){
          		$search['description'][$i][]=$description->firstChild->nodeValue;
          	}
          	$thumbnails = $groups->item($i)->getElementsByTagName("thumbnail");
          	foreach($thumbnails as $thumbnail){
          		$search['thumbnail'][$i][]=$thumbnail->getAttribute('url');
          	}
          	// and so on ......
          }
          echo "<pre>";
          print_r($search);
          

          What do you think about it ?
          Is there a better way ?

          Bye and thanks a lot again 😉

            Sorry the happines 😉

            I think this is far better:

            for ( $i = 0,$len = $this->groups->length; $i < $len; $i++ ) {
            			$title= $this->groups->item($i)->getElementsByTagName("title");
            			$this->result[$i]['title']=$title->item(0)->firstChild->nodeValue;
            			$description = $this->groups->item($i)->getElementsByTagName("description");
            			$this->result[$i]['description']=$description->item(0)->firstChild->nodeValue;
            			$thumbnail = $this->groups->item($i)->getElementsByTagName("thumbnail");
            			$this->result[$i]['thumbnail']=$thumbnail->item(0)->getAttribute('url');
            		}
            
              Write a Reply...