I am using using PHP and XMLDOM to retrieve data about a youtube video. Retrieving data from the generic elements is fine such as: <title></title>
. But I don't have any idea how to get the media namespace e.g: <media:statistics viewCount="1234567" />
. How would I get the value of viewCount
?
Here is my code:
/* Retrieve information for YouTube video */
$ytUser = "http://gdata.youtube.com/feeds/api/users/".$user."/uploads?orderby=published&start-index=1&max-results=1";
// Read feed in to DOM
$doc = new DOMDocument( '1.0', 'utf-8' );
$doc->load( $ytUser );
$doc->formatOutput = true;
$doc->preserveWhiteSpace = false;
// Video Author
$ytAuthor = $doc->getElementsByTagName( "name" )->item( 0 )->nodeValue;
// YT title
$ytTitle = $doc->getElementsByTagName( "title" )->item( 0 )->nodeValue;
// YT description
$des = $doc->getElementsByTagName( "description" )->item( 0 )->nodeValue;
$ytDescription = ( strlen( $des ) > 350 ) ? substr( $des, 0, 350 ) . '...' : $des;