使用 simpleXML 解析 foursquare KML 场地提要

发布于 2024-12-14 00:10:00 字数 1125 浏览 0 评论 0原文

我正在尝试使用 simpleXML 解析来自 foursqare 的 KML 场地提要,但我无法获取嵌套在描述中的场地 url。看起来 simpleXML 剥离了它。

详细信息:

foursqare kml feed 看起来像这样:

<kml>
 <Folder>
    <name>foursquare checkin history for X</name>
    <description>foursquare checkin history for X</description>
    <Placemark>
       <name>somevenuename</name>
       <description>@<a href="/v/somevenueurl">somevenuename</a>- a foursqareshout!</description>
       <updated>Wed, 02 Nov 11 17:00:05 +0000</updated>
       <published>Wed, 02 Nov 11 17:00:05 +0000</published>
       <visibility>1</visibility>
       <Point>
         <extrude>1</extrude>
         <altitudeMode>relativeToGround</altitudeMode> 
         <coordinates>xx.xxxxxx,yy.yyyyyy</coordinates>
       </Point>
    </Placemark>
    etc ...  

我对 simpleXMl 的调用是......嗯,简单:
$venue_items = simplexml_load_file($venue_kml_file);
有什么想法谁可以在 description 中保留 html 吗?

I am trying to parse a KML venue feed from foursqare with simpleXML but I cannot get the nested-in-desctription venue url. It looks like simpleXML strips it.

In detail:

The foursqare kml feed looks like this:

<kml>
 <Folder>
    <name>foursquare checkin history for X</name>
    <description>foursquare checkin history for X</description>
    <Placemark>
       <name>somevenuename</name>
       <description>@<a href="/v/somevenueurl">somevenuename</a>- a foursqareshout!</description>
       <updated>Wed, 02 Nov 11 17:00:05 +0000</updated>
       <published>Wed, 02 Nov 11 17:00:05 +0000</published>
       <visibility>1</visibility>
       <Point>
         <extrude>1</extrude>
         <altitudeMode>relativeToGround</altitudeMode> 
         <coordinates>xx.xxxxxx,yy.yyyyyy</coordinates>
       </Point>
    </Placemark>
    etc ...  

My call to simpleXMl is ... well, simple:
$venue_items = simplexml_load_file($venue_kml_file);
Any ideas who to preserve the html in description?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长不大的小祸害 2024-12-21 00:10:00

他们是对的。这是无效的 XML。不过,我使用正则表达式为您编写了一个解决方法。这可能有点hacky,但你只能用你所得到的来偿还,所以这里是:

$xml_string = <<<XML_STRING
<kml>
 <Folder>
    <name>foursquare checkin history for X</name>
    <description>foursquare checkin history for X</description>
    <Placemark>
       <name>somevenuename</name>
       <description>@<a href="/v/somevenueurl">somevenuename</a>- a foursqareshout!</description>
       <updated>Wed, 02 Nov 11 17:00:05 +0000</updated>
       <published>Wed, 02 Nov 11 17:00:05 +0000</published>
       <visibility>1</visibility>
       <Point>
         <extrude>1</extrude>
         <altitudeMode>relativeToGround</altitudeMode> 
         <coordinates>xx.xxxxxx,yy.yyyyyy</coordinates>
       </Point>
    </Placemark>
 </Folder>
 <Folder>
    <name>foursquare checkin history for X</name>
    <description>foursquare checkin history for X</description>
    <Placemark>
       <name>somevenuename</name>
       <description>@<a href="/v/somevenueurl222">somevenuename</a>- a foursqareshout!</description>
       <updated>Wed, 02 Nov 11 17:00:05 +0000</updated>
       <published>Wed, 02 Nov 11 17:00:05 +0000</published>
       <visibility>1</visibility>
       <Point>
         <extrude>1</extrude>
         <altitudeMode>relativeToGround</altitudeMode> 
         <coordinates>xx.xxxxxx,yy.yyyyyy</coordinates>
       </Point>
    </Placemark>
 </Folder>
</kml>    

XML_STRING;


preg_match_all( '%<Placemark>(.*?)</Placemark>%s', $xml_string, $placemarks, PREG_SET_ORDER );
for( $x = 0; $x < sizeof($placemarks); $x++ ){
    preg_match_all('%<description>(.*?)</description>%s', $placemarks[$x][1], $descriptions, PREG_SET_ORDER );
    for( $y = 0; $y < sizeof($descriptions); $y++ ){
        echo $descriptions[$y][1];
    }
}

希望有帮助......

They're right. This is invalid XML. However, I wrote a workaround for you using regex. It may be a bit hacky, but you can only make due with what you've been given, so here it is:

$xml_string = <<<XML_STRING
<kml>
 <Folder>
    <name>foursquare checkin history for X</name>
    <description>foursquare checkin history for X</description>
    <Placemark>
       <name>somevenuename</name>
       <description>@<a href="/v/somevenueurl">somevenuename</a>- a foursqareshout!</description>
       <updated>Wed, 02 Nov 11 17:00:05 +0000</updated>
       <published>Wed, 02 Nov 11 17:00:05 +0000</published>
       <visibility>1</visibility>
       <Point>
         <extrude>1</extrude>
         <altitudeMode>relativeToGround</altitudeMode> 
         <coordinates>xx.xxxxxx,yy.yyyyyy</coordinates>
       </Point>
    </Placemark>
 </Folder>
 <Folder>
    <name>foursquare checkin history for X</name>
    <description>foursquare checkin history for X</description>
    <Placemark>
       <name>somevenuename</name>
       <description>@<a href="/v/somevenueurl222">somevenuename</a>- a foursqareshout!</description>
       <updated>Wed, 02 Nov 11 17:00:05 +0000</updated>
       <published>Wed, 02 Nov 11 17:00:05 +0000</published>
       <visibility>1</visibility>
       <Point>
         <extrude>1</extrude>
         <altitudeMode>relativeToGround</altitudeMode> 
         <coordinates>xx.xxxxxx,yy.yyyyyy</coordinates>
       </Point>
    </Placemark>
 </Folder>
</kml>    

XML_STRING;


preg_match_all( '%<Placemark>(.*?)</Placemark>%s', $xml_string, $placemarks, PREG_SET_ORDER );
for( $x = 0; $x < sizeof($placemarks); $x++ ){
    preg_match_all('%<description>(.*?)</description>%s', $placemarks[$x][1], $descriptions, PREG_SET_ORDER );
    for( $y = 0; $y < sizeof($descriptions); $y++ ){
        echo $descriptions[$y][1];
    }
}

Hope that helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文