解析谷歌日历 XML 提要 [英] Parsing google calendar XML feed

查看:18
本文介绍了解析谷歌日历 XML 提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自公共谷歌日历的 XML 提要.看起来像这样:

I've got XML feed from public google calendar. Looks like this:

<?xml version='1.0' encoding='UTF-8'?>
    <feed xmlns='................' xmlns:gd='http://schemas.google.com/g/2005'>
        <id>http://www.google.com/calendar/feeds/........./public/full</id>
        <updated>2009-08-24T10:57:00.000Z</updated>
        <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'/>
            <title type='text'>Sports Events</title>
    .....
        <entry>
            <id>...........</id>
            <published>2009-08-14T00:29:58.000Z</published>
            <updated>2009-08-14T00:29:58.000Z</updated>
            <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'/>
..............
            <georss:where>
                <gml:Point>
                    <gml:pos>11.111111 -22.22222</gml:pos>
                </gml:Point>
            </georss:where>
            <gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'/>
            <gd:transparency value='http://schemas.google.com/g/2005#event.transparent'/>
            <gCal:uid value='.........@google.com'/>
            <gCal:sequence value='0'/>
            <gd:when startTime='2009-10-03' endTime='2009-10-04'/>

.............

现在到 PHP:

$calendar = simplexml_load_file('http://my.feed.com');
foreach ($calendar->entry as $item) {
    //here I get the whole <entry> node
    $gd = $item->children('http://schemas.google.com/g/2005');
    // now in $gd I have all nodes like <gd:XXXXX>
}

问题是如何从这里获取价值?

The problem is how to get value from here?

<gml:pos>11.111111 -22.22222</gml:pos>

它不存在于我的 $gd 变量中,如何获取此节点?

Its not present in my $gd variable, how to get this node?

推荐答案

我强烈推荐使用这个库:https://github.com/collegeman/coreylib.它会让一切从头到尾都变得容易得让人麻木.

I highly recommend using this library: https://github.com/collegeman/coreylib. It'll make everything from start to finish mind-numbingly easy.

这篇关于解析谷歌日历 XML 提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆