У меня есть xml со всеми видео из канала на YouTube, и я не знаю, как его анализировать
Ссылка http://gdata.youtube.com/feeds/base/users/vrelegume/uploads?alt=rss&orderby=published
Мой текущий код в Zend Framework:
public function videoAction ()
{
// XML-related routine
$xml = new DOMDocument('1.0', 'utf-8');
$content = $xml->appendChild(
$xml->createElement('content'));
$terms = urlencode('php 5 xml new');
$url = 'Link is http://gdata.youtube.com/feeds/base/users/vrelegume/uploads?alt=rss&orderby=published';
$query = $terms;
$serviceurl = $url . $query;
$dom = new DomDocument();
$dom->load("$url");
$i = 0;
foreach ($dom->documentElement->childNodes as $articles) {
if ($i<10) {
if ($articles->nodeType == 1) {
$itemXML = $content->appendChild($xml->createElement('item'));
foreach ($articles->childNodes as $item) {
$itemXML->appendChild($xml->createElement($item->nodeName, $item->textContent));
}
}
}
$i ++;
}
$output = $xml->saveXML();
// Both layout and view renderer should be disabled
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
Zend_Layout::getMvcInstance()->disableLayout();
// Set up headers and body
$this->_response->setHeader('Content-Type','text/xml; charset=utf-8')->setBody($output);
}
Как получить XML как:
<item>
<title>First video</title>
<link>http://www.youtube.com/watch?v=aZ6LrEvj2o0</link>
<thumb>*.jpg</thumb>
</item>
<item>
<title>Second video</title>
<link>...</link>
<thumb>*.jpg</thumb>
</item>
.
.
.