我想从RSS提要中读出一个带有Simple XML的特定属性。
项目示例:
<item>
<category>3500</category>
<category>20</category>
<category>17</category>
<title>Blabla</title>
<description>Blabla</description>
<content:encoded>Blabla</content:encoded>
<link>http://...</link>
<guid isPermaLink="false">http://...</guid>
<media:content url="http://image.jpg" medium="image">
<media:title type="html">caption needed</media:title>
</media:content>
<pubDate>Mon, 13 Aug 2012 11:40:53 +0200</pubDate>
</item>
我想阅读媒体:内容中的网址。
要读取我使用的其他标签:$xml->频道>项目[$i]->标题
要读取媒体网址属性,我尝试了:$xml->频道>项目[$i]->媒体>属性()->url
但这只返回 NULL。它与 :content 相关,它是一个命名空间。
元素的名称实际上是content
,而不是media
(这只是一个任意前缀,应该与命名空间相关联才能成为格式正确的XML)。与encoded
元素名称而不是content
相同。
$xml->item[0]->children('whatever-the-namespace-tied-to-media-is')->content->attributes()->url