View Full Version : Trouble Parsing Google Calendar XML
pelkin000
03-28-2008, 10:13 AM
Hey everyone,
I'm trying to do a project where I parse the xml from Google Calendar and then create events based on those to be used in a larger calendar project. I'm having some serious trouble getting Flash to cooperate though. Maybe you guys could take a look and let me know what I"m doing wrong:
public function xmlFeed(xmlURL:String, format:String):void {
var xmlReq:URLRequest = new URLRequest(xmlURL);
var xmlLoader:URLLoader = new URLLoader(xmlReq);
if (format == BASIC_XML) {
xmlLoader.addEventListener(Event.COMPLETE, xmlBasicLoaded);
} else if (format == GOOGLE_XML) {
xmlLoader.addEventListener(Event.COMPLETE, gCalLoaded);
} else if (format == ICAL) {
xmlLoader.addEventListener(Event.COMPLETE, xmlBasicLoaded);
}
}
private function gCalLoaded(evt:Event):void {
var xmlData:XML = XML(evt.target.data);
xmlData.ignoreWhitespace = true;
trace("====IN gCALLoaded====");
trace(xmlData.length());//1
trace(xmlData.localName());//name of the first tag "feed"
trace(xmlData.feed); //is a tag but returns a blank line in output
trace(xmlData.entry);// is a tag, but returns a blank line in output
}
Now I have already written the other basic function "xmlBasicLoaded" and it works just fine using the typical dot syntax. For some reason though, any use of dot syntax or even array syntax with the google code returns either a blank line or undefined. I've used other functions like children and elements and I can access deeper levels of the XML Structure that way, just not using any dot syntax (which makes life difficult).
The code for the xml can be found at this link (too much to post on here - would spam it):
http://www.google.com/calendar/feeds/up9ba31v77o3bvjfoh1soeqapk%40group.calendar.google .com/public/full?max-results=3&singleevents=true&orderby=starttime
Any help is much appreciated.
Thanks
pelkin000
03-28-2008, 06:27 PM
So i've also implemented Adobe's syndication package but again, everytime i try to get an entry, it is empty. Is this a problem with the XML? It seems odd that even though when I dump .toXMLString() it shows the XML, that anytime I try to access a parsed form of this XML, it shows as empty. Any help is much appreciated!
wvxvw
03-28-2008, 06:50 PM
First: xmlData.ignoreWhitespace = true; this line does nothing. ignoreWhitespace is a static property of XML, not an instance's var.
Second: most probably root node of the Google XML uses some namespace, try to get that namespace and, when you try to access the content of the loaded xml use it.
If this isn't the case, can you show an example of the XML which isn't loading?
pelkin000
04-01-2008, 01:56 AM
ok, thanks for the tips, I haven't done a whole lot of work with XML in Flash (if you couldn't tell...).
here is the actual XML that I'm dealing with:
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gCal="http://schemas.google.com/gCal/2005" xmlns:gd="http://schemas.google.com/g/2005">
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full</id>
<updated>2008-04-01T00:52:16.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">My New Cal</title>
<subtitle type="text">my new callll</subtitle>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/embed?src=42gfso849kbtlj4nammr6h2aho@group.calenda r.google.com"/>
<link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full"/>
<link rel="http://schemas.google.com/g/2005#batch" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/batch"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full?max-results=5&singleevents=true&orderby=starttime"/>
<author>
<name>Kyle Brekke</name>
<email>fake@fake.com</email>
</author>
<generator version="1.0" uri="http://www.google.com/calendar">Google Calendar</generator>
<openSearch:totalResults>4</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>5</openSearch:itemsPerPage>
<gd:where valueString="home"/>
<gCal:timezone value="America/Los_Angeles"/>
<entry>
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/k5r3660462pnk1bofn7i996v3c</id>
<published>2008-04-01T00:52:16.000Z</published>
<updated>2008-04-01T00:52:16.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">My events</title>
<content type="text"/>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/event?eid=azVyMzY2MDQ2MnBuazFib2ZuN2k5OTZ2M2MgNDJn ZnNvODQ5a2J0bGo0bmFtbXI2aDJhaG9AZw" title="alternate"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/k5r3660462pnk1bofn7i996v3c"/>
<author>
<name>My New Cal</name>
</author>
<gd:comments>
<gd:feedLink href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/k5r3660462pnk1bofn7i996v3c/comments"/>
</gd:comments>
<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="k5r3660462pnk1bofn7i996v3c@google.com"/>
<gCal:sequence value="0"/>
<gd:when startTime="2008-04-04" endTime="2008-04-05"/>
<gd:who rel="http://schemas.google.com/g/2005#event.organizer" valueString="My New Cal" email="42gfso849kbtlj4nammr6h2aho@group.calendar.google.c om"/>
<gd:where/>
</entry>
<entry>
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/diu25pct26l7u3pk4hsepq01ac</id>
<published>2008-04-01T00:52:06.000Z</published>
<updated>2008-04-01T00:52:06.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">some more events</title>
<content type="text"/>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/event?eid=ZGl1MjVwY3QyNmw3dTNwazRoc2VwcTAxYWMgNDJn ZnNvODQ5a2J0bGo0bmFtbXI2aDJhaG9AZw" title="alternate"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/diu25pct26l7u3pk4hsepq01ac"/>
<author>
<name>My New Cal</name>
</author>
<gd:comments>
<gd:feedLink href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/diu25pct26l7u3pk4hsepq01ac/comments"/>
</gd:comments>
<gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
<gd:transparency value="http://schemas.google.com/g/2005#event.opaque"/>
<gCal:uid value="diu25pct26l7u3pk4hsepq01ac@google.com"/>
<gCal:sequence value="0"/>
<gd:when startTime="2008-04-03T13:00:00.000-07:00" endTime="2008-04-03T14:00:00.000-07:00"/>
<gd:who rel="http://schemas.google.com/g/2005#event.organizer" valueString="My New Cal" email="42gfso849kbtlj4nammr6h2aho@group.calendar.google.c om"/>
<gd:where/>
</entry>
<entry>
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/h5dms5jdf1tgfv5bc8hi70vatg</id>
<published>2008-04-01T00:52:01.000Z</published>
<updated>2008-04-01T00:52:01.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">another event</title>
<content type="text"/>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/event?eid=aDVkbXM1amRmMXRnZnY1YmM4aGk3MHZhdGcgNDJn ZnNvODQ5a2J0bGo0bmFtbXI2aDJhaG9AZw" title="alternate"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/h5dms5jdf1tgfv5bc8hi70vatg"/>
<author>
<name>My New Cal</name>
</author>
<gd:comments>
<gd:feedLink href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/h5dms5jdf1tgfv5bc8hi70vatg/comments"/>
</gd:comments>
<gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
<gd:transparency value="http://schemas.google.com/g/2005#event.opaque"/>
<gCal:uid value="h5dms5jdf1tgfv5bc8hi70vatg@google.com"/>
<gCal:sequence value="0"/>
<gd:when startTime="2008-04-02T10:00:00.000-07:00" endTime="2008-04-02T11:00:00.000-07:00"/>
<gd:who rel="http://schemas.google.com/g/2005#event.organizer" valueString="My New Cal" email="42gfso849kbtlj4nammr6h2aho@group.calendar.google.c om"/>
<gd:where/>
</entry>
<entry>
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/igjqannh3v23e2ructbkoclfa4</id>
<published>2008-04-01T00:51:55.000Z</published>
<updated>2008-04-01T00:51:55.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">temporary event</title>
<content type="text"/>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/event?eid=aWdqcWFubmgzdjIzZTJydWN0YmtvY2xmYTQgNDJn ZnNvODQ5a2J0bGo0bmFtbXI2aDJhaG9AZw" title="alternate"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/igjqannh3v23e2ructbkoclfa4"/>
<author>
<name>My New Cal</name>
</author>
<gd:comments>
<gd:feedLink href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/igjqannh3v23e2ructbkoclfa4/comments"/>
</gd:comments>
<gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
<gd:transparency value="http://schemas.google.com/g/2005#event.opaque"/>
<gCal:uid value="igjqannh3v23e2ructbkoclfa4@google.com"/>
<gCal:sequence value="0"/>
<gd:when startTime="2008-03-31T09:30:00.000-07:00" endTime="2008-03-31T10:30:00.000-07:00"/>
<gd:who rel="http://schemas.google.com/g/2005#event.organizer" valueString="My New Cal" email="42gfso849kbtlj4nammr6h2aho@group.calendar.google.c om"/>
<gd:where/>
</entry>
</feed>
As you can see there is the first set of data that describes the owner/update dates of the calendar itself. Then after that the actual events are delineated by the <entry> tag. Unfortunately I can't access anything using the logical namespaces (feed, entry, author, etc). Any thoughts at all?
wvxvw
04-01-2008, 09:15 AM
xmlns="http://www.w3.org/2005/Atom" is a namespace the XML uses;
trace(xmlData.*::entry.toXMLString());
//or
var ns:Namespace = xmlData.namespace();
trace(xmlData.ns::entry.toXMLString());
Eg:
var xml:XML = <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gCal="http://schemas.google.com/gCal/2005" xmlns:gd="http://schemas.google.com/g/2005">
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full</id>
<updated>2008-04-01T00:52:16.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">My New Cal</title>
<subtitle type="text">my new callll</subtitle>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/embed?src=42gfso849kbtlj4nammr6h2aho@group.calenda r.google.com"/>
<link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full"/>
<link rel="http://schemas.google.com/g/2005#batch" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/batch"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full?max-results=5&singleevents=true&orderby=starttime"/>
<author>
<name>Kyle Brekke</name>
<email>brekke.kyle@gmail.com</email>
</author>
<generator version="1.0" uri="http://www.google.com/calendar">Google Calendar</generator>
<openSearch:totalResults>4</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>5</openSearch:itemsPerPage>
<gd:where valueString="home"/>
<gCal:timezone value="America/Los_Angeles"/>
<entry>
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/k5r3660462pnk1bofn7i996v3c</id>
<published>2008-04-01T00:52:16.000Z</published>
<updated>2008-04-01T00:52:16.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">My events</title>
<content type="text"/>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/event?eid=azVyMzY2MDQ2MnBuazFib2ZuN2k5OTZ2M2MgNDJn ZnNvODQ5a2J0bGo0bmFtbXI2aDJhaG9AZw" title="alternate"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/k5r3660462pnk1bofn7i996v3c"/>
<author>
<name>My New Cal</name>
</author>
<gd:comments>
<gd:feedLink href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/k5r3660462pnk1bofn7i996v3c/comments"/>
</gd:comments>
<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="k5r3660462pnk1bofn7i996v3c@google.com"/>
<gCal:sequence value="0"/>
<gd:when startTime="2008-04-04" endTime="2008-04-05"/>
<gd:who rel="http://schemas.google.com/g/2005#event.organizer" valueString="My New Cal" email="42gfso849kbtlj4nammr6h2aho@group.calendar.google.c om"/>
<gd:where/>
</entry>
<entry>
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/diu25pct26l7u3pk4hsepq01ac</id>
<published>2008-04-01T00:52:06.000Z</published>
<updated>2008-04-01T00:52:06.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">some more events</title>
<content type="text"/>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/event?eid=ZGl1MjVwY3QyNmw3dTNwazRoc2VwcTAxYWMgNDJn ZnNvODQ5a2J0bGo0bmFtbXI2aDJhaG9AZw" title="alternate"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/diu25pct26l7u3pk4hsepq01ac"/>
<author>
<name>My New Cal</name>
</author>
<gd:comments>
<gd:feedLink href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/diu25pct26l7u3pk4hsepq01ac/comments"/>
</gd:comments>
<gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
<gd:transparency value="http://schemas.google.com/g/2005#event.opaque"/>
<gCal:uid value="diu25pct26l7u3pk4hsepq01ac@google.com"/>
<gCal:sequence value="0"/>
<gd:when startTime="2008-04-03T13:00:00.000-07:00" endTime="2008-04-03T14:00:00.000-07:00"/>
<gd:who rel="http://schemas.google.com/g/2005#event.organizer" valueString="My New Cal" email="42gfso849kbtlj4nammr6h2aho@group.calendar.google.c om"/>
<gd:where/>
</entry>
<entry>
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/h5dms5jdf1tgfv5bc8hi70vatg</id>
<published>2008-04-01T00:52:01.000Z</published>
<updated>2008-04-01T00:52:01.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">another event</title>
<content type="text"/>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/event?eid=aDVkbXM1amRmMXRnZnY1YmM4aGk3MHZhdGcgNDJn ZnNvODQ5a2J0bGo0bmFtbXI2aDJhaG9AZw" title="alternate"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/h5dms5jdf1tgfv5bc8hi70vatg"/>
<author>
<name>My New Cal</name>
</author>
<gd:comments>
<gd:feedLink href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/h5dms5jdf1tgfv5bc8hi70vatg/comments"/>
</gd:comments>
<gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
<gd:transparency value="http://schemas.google.com/g/2005#event.opaque"/>
<gCal:uid value="h5dms5jdf1tgfv5bc8hi70vatg@google.com"/>
<gCal:sequence value="0"/>
<gd:when startTime="2008-04-02T10:00:00.000-07:00" endTime="2008-04-02T11:00:00.000-07:00"/>
<gd:who rel="http://schemas.google.com/g/2005#event.organizer" valueString="My New Cal" email="42gfso849kbtlj4nammr6h2aho@group.calendar.google.c om"/>
<gd:where/>
</entry>
<entry>
<id>http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/igjqannh3v23e2ructbkoclfa4</id>
<published>2008-04-01T00:51:55.000Z</published>
<updated>2008-04-01T00:51:55.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
<title type="text">temporary event</title>
<content type="text"/>
<link rel="alternate" type="text/html" href="http://www.google.com/calendar/event?eid=aWdqcWFubmgzdjIzZTJydWN0YmtvY2xmYTQgNDJn ZnNvODQ5a2J0bGo0bmFtbXI2aDJhaG9AZw" title="alternate"/>
<link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/igjqannh3v23e2ructbkoclfa4"/>
<author>
<name>My New Cal</name>
</author>
<gd:comments>
<gd:feedLink href="http://www.google.com/calendar/feeds/42gfso849kbtlj4nammr6h2aho%40group.calendar.google .com/public/full/igjqannh3v23e2ructbkoclfa4/comments"/>
</gd:comments>
<gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
<gd:transparency value="http://schemas.google.com/g/2005#event.opaque"/>
<gCal:uid value="igjqannh3v23e2ructbkoclfa4@google.com"/>
<gCal:sequence value="0"/>
<gd:when startTime="2008-03-31T09:30:00.000-07:00" endTime="2008-03-31T10:30:00.000-07:00"/>
<gd:who rel="http://schemas.google.com/g/2005#event.organizer" valueString="My New Cal" email="42gfso849kbtlj4nammr6h2aho@group.calendar.google.c om"/>
<gd:where/>
</entry>
</feed>;
trace(xml.*::entry[0].toXMLString());
pelkin000
04-02-2008, 04:52 AM
wow, my new hero! :) thank you sooo much!
h8ids
03-13-2010, 06:14 PM
I'm curious to know if you got the calendar to wok through Flash. :D
Awhile back I had contacted you regarding this endeavor and have been working with the source files you shared with me.
Unfortunately I haven't been able to get Flash to present the XML data from a Public calendar.
Scratching my head. :confused:
Do you have a live example?
Thanks again,
David
pelkin000
12-30-2010, 05:26 PM
Sorry for the delayed response. For everyone's sake I thought I mention that the most likely culprit in situations like this is the crossdomain.xml issue. Its doubtful that Goog Calendar had a crossdomain.xml file that gave you permission to access their resources. A work around is to use a php file on your domain as a proxy (see cURL, or google crossdomain php proxy). Once the security issues go away, I think your swf will find access to the data it needs.
the binary
12-30-2010, 05:45 PM
@pelking
please get used to insert some linebreaks..
reading a 15 meter long text line isn't fun at all.. ;)
thanks in advance..
cheers
heh. i think that may actually be from the code posted by wvxvw.
heh. well... actually i cant really tell...
the binary
12-30-2010, 10:04 PM
heh. i think that may actually be from the code posted by wvxvw.
heh. well... actually i cant really tell...
ups, guess you're right.. *blush ;)
nevermind.. shame on you wvxwv .. ;)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.