Hiya,
I've consistently had an issue with parsing XML with PHP and not really found "the right way" or at least a standardised way of parsing XML files.
Firstly i'm trying to parse this:
<item>
<title>2884400</title>
<description><![CDATA[ ><img width="126" alt="" src="http://userserve-ak.last.fm/serve/126/27319921.jpg" /> ]]></description>
<link>http://www.last.fm/music/+noredirect/Beatles/+images/27319921</link>
<author>anne710</author>
<pubDate>Tue, 21 Apr 2009 16:12:31 +0000</pubDate>
<guid>http://www.last.fm/music/+noredirect/Beatles/+images/27319921</guid>
<media:content url="http://userserve-ak.last.fm/serve/_/27319921/Beatles+2884400.jpg" fileSize="13065" type="image/jpeg" expression="full" width="126" height="126" />
<media:thumbnail url="http://userserve-ak.last.fm/serve/126/27319921.jpg" type="image/jpeg" width="126" height="126" />
</item>
I'm using this code:
$doc = new DOMDocument();
$doc->load('http://ws.audioscrobbler.com/2.0/artist/beatles/images.rss');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
);
array_push($arrFeeds, $itemRSS);
}
Now I want to get the "media:content" and "media:thumbnail" url attributes, how would i do that? Now i think i should be using DOMElement::getAttribute but i haven't managed to get it to work :/ Can anyone shed some light on this, and also let me know if this is a good way to parse XML?
Regards, Shadi