search

Home  >  Q&A  >  body text

Simple XML - handling colons in nodes

<p>I'm trying to read an RSS feed from Flickr, but it contains some nodes that Simple XML can't parse (like media:thumbnail, flickr:profile, etc.). <br /><br />How do I solve this problem? When I look at the documentation for the DOM, I get a headache. So I want to avoid using DOM because I don't want to learn it. <br /><br />By the way, I'm trying to get thumbnails. </p><p><br /></p>
P粉713866425P粉713866425507 days ago579

reply all(2)I'll reply

  • P粉087074897

    P粉0870748972023-07-30 00:29:27

    In the latest version, you can now use curly braces to reference nodes with colons.

    $item->{'itunes:duration'}

    reply
    0
  • P粉311423594

    P粉3114235942023-07-30 00:22:14

    The solution is explained in this great article. You need to use the children() method to access the XML element containing the namespace. The following code snippet is taken from the article:

    $feed = simplexml_load_file('http://www.sitepoint.com/recent.rdf'); 
    foreach ($feed->item as $item) { 
        $ns_dc = $item->children('http://purl.org/dc/elements/1.1/'); 
        echo $ns_dc->date; 
    }

    reply
    0
  • Cancelreply