PHP xml parse fail :(

I really can’t see why this isn’t working. Someone please point out what I’m doing wrong.

I really don’t know why I struggle with this. I get some stuff to work and then try something similar and have to bang my head against the desk.

Please help.

PHP Code:
$output = $output.‘<p><a target=“_blank” href="’.$xml_link.‘">XML link</a></p>’;
$xml = simplexml_load_file($xml_link);
foreach ($xml as $geoname) {
$lat = $geoname->lat;
$lng = $geoname->lng;
$population = $geoname->population;
$latlon = $lat.‘,’.$lng;

$output = $output.'&lt;p&gt;Population '.$population.'&lt;/p&gt;&lt;p&gt; Latitude /Longitude '.$latlon.'&lt;/p&gt;';

XML I am parsing is:
<toponymName>San Javier</toponymName>
<name>San Javier</name>
<fclName>country, state, region,…</fclName>
<fcodeName>third-order administrative division</fcodeName>
<adminName3>San Javier</adminName3>
<alternateName lang=“link”>;/alternateName&gt;&lt;timezone dstOffset=“2.0” gmtOffset=“1.0”>Europe/Madrid</timezone>

Try $xml->lat instead. The initial wrapper (geoname) is consumed during the xml parsing.

Are you getting an error?

Here’s a good way to validate the file or show errors:

Also you can do a print_r to see the structure if you can’t access a node.

StarLion Thanks…now I know "The initial wrapper (geoname) is consumed during the xml parsing. ", that helps a great deal.