我在我的 php 应用程序中使用 simpleXML。
我需要用“媒体组”包装我的媒体元素。这是到目前为止的xml输出:
...
<item>
<title>02:15</title>
<link>http://www.realcardio.com</link>
<description>Workout with Hugo to get bigger biceps</description>
<pubDate>08/14/2012</pubDate>
<media:credit role="author">workout title goes here</media:credit>
<media:content url="http://youtu.be/21EpHRJTT34"/>
<media:thumbnail url="http://img.youtube.com/vi/21EpHRJTT34/1.jpg"/>
<jwplayer:start>150</jwplayer:start>
<jwplayer:duration>285</jwplayer:duration>
<jwplayer:backcolor>#FFCC00</jwplayer:backcolor>
<jwplayer:message>This is a test message to display to the user</jwplayer:message>
<jwplayer:routineID>26</jwplayer:routineID>
</item>
...
我只需要像这样对媒体元素进行分组:
<media:group>
<media:credit role="author">workout title goes here</media:credit>
<media:content url="http://youtu.be/21EpHRJTT34"/>
<media:thumbnail url="http://img.youtube.com/vi/21EpHRJTT34/1.jpg"/>
</media:group>
到目前为止,这是我用来创建 xml 文件的代码:
...
$item = $channel->addChild( 'item' );
$item->addChild( 'title', $minsandsecs );
$item->addChild( 'link', 'http://www.realcardio.com' );
$item->addChild( 'description', $viddesc );
$item->addChild( 'pubDate', '08/14/2012' );
$mediaCredit = $item->addChild( 'credit', 'workout title goes here','http://search.yahoo.com/mrss/' );
$mediaCredit->addAttribute( 'role', 'author' );
$mediaContent = $item->addChild( 'content', '', 'http://search.yahoo.com/mrss/' );
$mediaContent->addAttribute( 'url', $vidsource );
$mediaThumbnail = $item->addChild( 'thumbnail', '', 'http://search.yahoo.com/mrss/' );
$mediaThumbnail->addAttribute( 'url', $imgloc );
$item->addChild( 'start',$vidstart, 'http://developer.longtailvideo.com/trac/wiki/FlashFormats' );
$item->addChild( 'duration',$viddur, 'http://developer.longtailvideo.com/trac/wiki/FlashFormats' );
$item->addChild( 'backcolor',$vidbackcolor, 'http://developer.longtailvideo.com/trac/wiki/FlashFormats' );
$item->addChild( 'message', $vidmessage, 'http://developer.longtailvideo.com/trac/wiki/FlashFormats' );
$item->addChild( 'routineID', $routineID, 'http://developer.longtailvideo.com/trac/wiki/FlashFormats' );
...
我敢肯定,我忽略了一些简单的事情。谢谢!