Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

xml - PHP parsing a georss namespace with simpleXML

Trying to parse out lat/lon from a google maps rss feed:

$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;

The title shows up alright, but point gives me nothing. Each node looks like this:

<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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<?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;
    } 
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...