problem using SimpleXML

hello,! i’m begining with simpleXML
here is my xml file (GEORSS)



<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:mappoint="http://virtualearth.msn.com/apis/annotate#">
<channel>
        <title>Zones etudes KSpot</title>
        <link></link>
        <description>Localisation des zones d'etudes disponible dans KSPOT adi pour Kyris mai 2007</description>
        <mappointIntlCode>cht</mappointIntlCode>
    <item>
        <title>590510000</title>
        <link></link>
        <description>0;Croix:3;Marc en Baroeul:2,5;Orvault;</description>
        <geo:lat> 50.5388373881578</geo:lat>
        <geo:long> 2.80992893502116</geo:long>
    </item>
    <item>
        <title>596230000</title>
        <link></link>
        <description>0;Croix:15,5;Marc en Baroeul:0;Orvault;</description>
        <geo:lat> 50.0355881731957</geo:lat>
        <geo:long> 3.14659385941923</geo:long>
    </item>
    <item>
        <title>590520000</title>
        <link></link>
        <description>0;Croix:4;Marc en Baroeul:3,5;Orvault;</description>
        <geo:lat> 50.5174185242504</geo:lat>
        <geo:long> 2.89355007000268</geo:long>
    </item>
    <item>
        <title>593200000</title>
        <link></link>
        <description>0;Croix:0;Marc en Baroeul:2,2;Orvault;</description>
        <geo:lat> 50.5635185725987</geo:lat>
        <geo:long> 2.83156916499138</geo:long>
    </item>
</channel>
</rss>

As you can see a tag is geo:lat

these two points : is a real problem with this code:

<html><head/><body>
<?php
$rss = simplexml_load_file('iris.xml');
foreach ($rss->channel as $channel) {
    foreach ($channel->item as $item) {    
        foreach ($item->description as $description) {
            print "longitude : {$item->geo:lat} <br />n";
            }
    }
  }
?> 
</body></html>

I can’t change the tag name , of course.
Anybody can help me ? thanks in advance

the tag isn’t ‘geo:lat’ but ‘lat’.
geo: is just a prefix, to be used with a seperate namespace.
havn’t tryed but it should be possible to just use $item->lat

otherwise take a look at xpath:
http://php.net/simplexml-element-xpath
http://php.net/simplexml-element-registerXPathNamespace

edit: broken links

well no , this is not working…

Your links are broken

sry, right links are:
http://php.net/simplexml-element-xpath
http://php.net/simplexml-element-registerXPathNamespace

Sponsor our Newsletter | Privacy Policy | Terms of Service