2011-04-01 57 views
3

試圖從谷歌解析出經/緯度地圖RSS Feed:PHP解析的GeoRSS命名空間使用SimpleXML

$file = "http://maps.google.com/maps/ms?ie=UTF8&hl=en&vps=1&jsv=327b&msa=0&output=georss&msid=217909142388190116501.000473ca1b7eb5750ebfe"; 
$xml = simplexml_load_file($file);  
$loc = $xml->channel->item; 
echo $loc[0]->title; 
echo $loc[0]->point; 

標題正常的顯示,但點給我什麼。每個節點看起來是這樣的:

<item> 
    <guid isPermaLink="false">0004740950fd067393eb4</guid> 
    <pubDate>Sun, 20 Sep 2009 21:47:49 +0000</pubDate> 
    <title>Big Wong King Restaurant</title> 
    <description><![CDATA[<div dir="ltr">$4.99 full meals!</div>]]></description> 
    <author>neufuture</author> 
    <georss:point> 
     40.716236 -73.998413 
    </georss:point> 
    <georss:elev>0.000000</georss:elev> 
    </item> 

回答

1

試試這個:

<?php 
    $file = "http://maps.google.com/maps/ms?ie=UTF8&hl=en&vps=1&jsv=327b&msa=0&output=georss&msid=217909142388190116501.000473ca1b7eb5750ebfe"; 
    $xml = simplexml_load_file($file); 
    $loc = $xml->channel->item; 
    foreach ($loc->children('http://www.georss.org/georss') as $geo) { 
     echo $geo; 
    } 
?> 

結帳這個Zend article for working with namespaces in XML

+0

Zend的文章鏈接被打破 – Nate 2013-07-09 23:20:39