Location: PHPKode > scripts > YouTube Video API > google_data.class.php
<?php
class google_data
{
	public function read($feed_url)
	{
		libxml_use_internal_errors(true); 
		libxml_clear_errors(); 
		$document = new DOMDocument(); 
		$document->loadXML(file_get_contents($feed_url));
		$xpath = new DOMXPath($document); 
		$xpath->registerNamespace("atom", 		"http://www.w3.org/2005/Atom");
		$xpath->registerNamespace("openSearch", "http://a9.com/-/spec/opensearch/1.1/");
		$xpath->registerNamespace("gml", 		"http://www.opengis.net/gml");
		$xpath->registerNamespace("georss", 	"http://www.georss.org/georss");
		$xpath->registerNamespace("media", 		"http://search.yahoo.com/mrss/");
		$xpath->registerNamespace("batch", 		"http://schemas.google.com/gdata/batch");
		$xpath->registerNamespace("yt", 		"http://gdata.youtube.com/schemas/2007");
		$xpath->registerNamespace("gd", 		"http://schemas.google.com/g/2005");
		return $xpath;
	}
	
	public function get_node($xpath, $query, $in = null)
	{
		$nodes = $in == null ? $xpath->query($query) : $xpath->query($query, $in);
		if ($nodes)
		{
			foreach ($nodes as $node)
			{
				return $node;
			}
		}
		return null;
	}
	
	public function get_node_value($xpath, $query, $in, $default)
	{
		$node = $this->get_node($xpath, $query, $in);
		return isset($node) ? $node->nodeValue : $default;
	}
	
	public function get_node_attr($xpath, $query, $in, $attr, $default)
	{
		$node = $this->get_node($xpath, $query, $in);
		return isset($node) ? $node->getAttribute($attr) : $default;
	}
}
?>
Return current item: YouTube Video API