SimpleXML: Working with XML containing namespaces

后端 未结 3 592
猫巷女王i
猫巷女王i 2020-11-29 13:06

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


  
    35         


        
3条回答
  •  孤街浪徒
    2020-11-29 13:33

    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

提交回复
热议问题