I want to read out a specific attribute with Simple XML from an RSS feed.
Example of an item:
<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>
I want to read the url which is in media:content.
To read the other tags I used : $xml->channel->item[$i]->title
To read the media url attribute I tried : $xml->channel->item[$i]->media->attributes()->url
But this just returns NULL. It’s something related to :content which is a namespace.
The name of the element is actually
content, notmedia(which is just an arbitrary prefix which should be associated with a namespace to be well-formed XML). Same withencodedbeing the element name instead ofcontent.