Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing XML using PHP
    primarykey
    data
    text
    <p>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.</p> <p>Firstly i'm trying to parse this:</p> <pre><code> &lt;item&gt; &lt;title&gt;2884400&lt;/title&gt; &lt;description&gt;&lt;![CDATA[ &gt;&lt;img width="126" alt="" src="http://userserve-ak.last.fm/serve/126/27319921.jpg" /&gt; ]]&gt;&lt;/description&gt; &lt;link&gt;http://www.last.fm/music/+noredirect/Beatles/+images/27319921&lt;/link&gt; &lt;author&gt;anne710&lt;/author&gt; &lt;pubDate&gt;Tue, 21 Apr 2009 16:12:31 +0000&lt;/pubDate&gt; &lt;guid&gt;http://www.last.fm/music/+noredirect/Beatles/+images/27319921&lt;/guid&gt; &lt;media:content url="http://userserve-ak.last.fm/serve/_/27319921/Beatles+2884400.jpg" fileSize="13065" type="image/jpeg" expression="full" width="126" height="126" /&gt; &lt;media:thumbnail url="http://userserve-ak.last.fm/serve/126/27319921.jpg" type="image/jpeg" width="126" height="126" /&gt; &lt;/item&gt; </code></pre> <p>I'm using this code:</p> <pre><code>$doc = new DOMDocument(); $doc-&gt;load('http://ws.audioscrobbler.com/2.0/artist/beatles/images.rss'); $arrFeeds = array(); foreach ($doc-&gt;getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' =&gt; $node-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;nodeValue, 'desc' =&gt; $node-&gt;getElementsByTagName('description')-&gt;item(0)-&gt;nodeValue, 'link' =&gt; $node-&gt;getElementsByTagName('link')-&gt;item(0)-&gt;nodeValue, 'date' =&gt; $node-&gt;getElementsByTagName('pubDate')-&gt;item(0)-&gt;nodeValue ); array_push($arrFeeds, $itemRSS); } </code></pre> <p>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?</p> <p>Regards, Shadi</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload