JW プレーヤーを使用して、XML プレイリストを読み込みます。XMLファイルを手動で書くとうまくいきますが、phpを使って解析するとうまくいきません...
私はそれを次のようにしたい:
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:jwplayer="http://developer.longtailvideo.com/trac/">
<channel>
<item>
<title>Albert</title>
<media:content url="../movies/hi.mp4" />
<description></description>
<jwplayer:duration>10</jwplayer:duration>
</item>
</channel>
</rss>
最初の問題は<rss version="2.0" ...
、ヘッダーを次のように強制することです。<?xml version="1.0"?>
2番目の問題は、<media:content url="" ...
PHPでそれを印刷するにはどうすればよいですか?
3つ目の問題は末尾のRSSの付け方です</rss>
私のコードは次のとおりです。
<?php
$channel = array();
$channel [] = array(
'title' => 'Albert',
'content' => 'filmer/c1.jpg',
'duration' => "10"
);
$channel [] = array(
'title' => 'Claud',
'content' => 'filmer/c2.jpg',
'duration' => "10"
);
$doc = new DOMDocument();
$doc->formatOutput = true;
$r = $doc->createElement( "channel" );
$doc->appendChild( $r );
foreach( $channel as $item )
{
$b = $doc->createElement( "item" );
$title = $doc->createElement( "title" );
$title->appendChild(
$doc->createTextNode( $item['title'] )
);
$b->appendChild( $title );
$content = $doc->createElement( "media:content" );
$content->appendChild(
$doc->createTextNode( $item['content'] )
);
$b->appendChild( $content );
$duration = $doc->createElement( "jwplayer:duration" );
$duration->appendChild(
$doc->createTextNode( $item['duration'] )
);
$b->appendChild( $duration );
$r->appendChild( $b );
}
echo $doc->saveHTML();
$doc->save("write.xml")
?>
何か案は?私は PHP/XML の初心者です。申し訳ありません :/