Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing google calendar XML feed

Tags:

php

xml

simplexml

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='[email protected]'/>
            <gCal:sequence value='0'/>
            <gd:when startTime='2009-10-03' endTime='2009-10-04'/>

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

Now to 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>

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

like image 945
6bytes Avatar asked Aug 28 '09 13:08

6bytes


People also ask

Does Google Calendar have an RSS feed?

Google Calendar + RSS by Zapier IntegrationsZapier lets you send info between Google Calendar and RSS by Zapier automatically—no code required. Triggers when an event is cancelled or deleted. Power your own Zapier RSS feed.


1 Answers

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

like image 198
Kenneth Reitz Avatar answered Nov 15 '22 08:11

Kenneth Reitz