Php 输出具有媒体组属性的xml文件

Php 输出具有媒体组属性的xml文件,php,xml,xml-parsing,Php,Xml,Xml Parsing,我在php应用程序中使用simpleXML 我需要用“媒体组”包装我的媒体元素。 以下是迄今为止的xml输出: ... <item> <title>02:15</title> <link>http://www.realcardio.com</link> <description>Workout with Hugo to get bigger biceps</description> <pubDate>

我在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>
...
我确信这是我忽略的一些简单的事情。
谢谢

您没有在任何地方创建
元素,这是主要问题。否则,您所缺少的就是在
addChild()
中指定名称空间前缀
media:


如果要创建名称空间,请阅读以下内容
<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>
...
$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' );
...
$mediaGroup = $item->addChild('media:group', '', 'http://search.yahoo.com/mrss/');

$mediaCredit = $mediaGroup->addChild('media:credit', 'workout title goes here', 'http://search.yahoo.com/mrss/');
$mediaCredit->addAttribute('role', 'author');

$mediaContent = $mediaGroup->addChild('media:content', '', 'http://search.yahoo.com/mrss/');
$mediaContent->addAttribute('url', $vidsource);

$mediaThumbnail = $mediaGroup->addChild('media:thumbnail', '', 'http://search.yahoo.com/mrss/');
$mediaThumbnail->addAttribute('url', $imgloc);