Simple XML - handling colons in nodes
P粉713866425
P粉713866425 2023-07-29 08:35:35
0
2
575
<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粉713866425
P粉713866425

reply all(2)
P粉087074897

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

$item->{'itunes:duration'}
P粉311423594

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; 
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template