PDA

View Full Version : XML Tags with ':' in them: ex. <geo:lat></geo:lat> or <geo:long></geo:long>



inchecksolution
24 May 2011, 10:51 AM
Hello WebDev World!

I have a quick question, and hopefully a quick answer!! I am retrieving an external XML document and I'm having no trouble accessing information contained in regular XML tags:




$xml_str = file_get_contents($url,0);
$xml = simplexml_load_string($xml_str);
$data = $xml->channel->item;

$title = $data->title;
$description = $data->description;


The ABOVE works fine! BUT when I run into a tag such as <geo:lat> it won't work:



$lat = $data->geo:lat; //does not return the data properly

//I also tried:

$lat = $data->{'geo:lat'} //doesn't work either


Can any please let me know how to access that <geo:lat> tag? I figure out this is something to do with something called namespaces, but I have no idea how to handle it and can't find a straight answer.

THANK YOU FOR ANY HELP!!!!!