Parsing XML Nodes with Colons Using Simple XML
Accessing XML elements containing colons (:) in their names can pose a challenge when using the SimpleXML extension. Nodes like "media:thumbnail" and "flickr:profile" are often encountered in feeds such as Flickr's RSS, hindering straightforward retrieval.
To navigate this obstacle without resorting to the DOM, one can employ the children() method of SimpleXML. This method allows for accessing elements by providing a namespace URI.
For instance, to retrieve the thumbnail from a Flickr RSS feed, one can utilize the following code:
$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; }
The above is the detailed content of How Can I Parse XML Nodes with Colons Using SimpleXML?. For more information, please follow other related articles on the PHP Chinese website!