0
我在我的php应用程序中使用了simpleXML。输出具有媒体组属性的xml文件
我需要用'媒体组'来包装我的媒体元素。 这是迄今为止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');
...
我敢肯定,这是简单的,我可以俯瞰。 谢谢!
你想创建命名空间,阅读这个http://stackoverflow.com/questions/1306313/generate-xml-with-namespace-uri-in-php – user1477388 2012-08-14 19:26:40