1

I am trying to get to the geo information off the google-picasa API. This is the original XML:

<georss:where>
  <gml:Point>
    <gml:pos>35.669998 139.770004</gml:pos>
  </gml:Point>
</georss:where>

I already have come this far, with:

$ns_geo=$item->children($namespace['georss']);
$geo=$ns_geo->children($namespace['gml']);

var_dump($geo) will output

object(SimpleXMLElement)#34 (1) { 
  ["Point"]=> object(SimpleXMLElement)#30 (1) { 
    ["pos"]=> string(18) "52.373801 4.890935" 
  } 
} 

but

echo (string)$geo->position or (string)$geo->position->pos; 

will give me nothing. Is there something obvious that i am doing wrong?

3 Answers 3

4

You could work with XPath and registerXPathNamespace():

$xml->registerXPathNamespace("georss", "http://www.georss.org/georss");
$xml->registerXPathNamespace("gml", "http://www.opengis.net/gml");
$pos = $xml->xpath("/georss:where/gml:Point/gml:pos");

From the docs, emphasis mine:

registerXPathNamespace […] Creates a prefix/ns context for the next XPath query.

More ways to handle namespaces in SimpleXML can be found here, for example:
Stuart Herbert On PHP - Using SimpleXML To Parse RSS Feeds

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, I came to the same conclusion this worked $geo = $feed->xpath('//gml:pos');echo $geo[0]; maybe the other way can't handle nested namespace elements
actually, I misspelled something.$geo->point should be $geo->Point (uppercase)
0
echo $geo->pos[0];

1 Comment

This method won't access namespaces
0

This is how I did it without using xpath:

$georss = $photo->children('http://www.georss.org/georss');
$coords;
if($georss->count()>0) {
    $gml = $georss->children('http://www.opengis.net/gml');
    if($gml->count()>0) {
        if(isset($gml->Point->pos)) {
            $coords = $gml->Point->pos;
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.