Submit XML to Google Calendar

I have an XML file with workshops that I would like to submit to the Google calendar. The XML file is maintained by someone else and is updated regularly, so I would like to make it so that Google automatically captures these changes.

I do not have much experience with this, so I hope someone can point me in the right direction.

This is an example of XML that I want to process.

(XML file: "seminar.xml")

<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="ical.xsl"?> <seminars> <lastupdate>20150707</lastupdate> <seminar> <speaker>A. Einstein</speaker> <location>Zurich</location> <date>20150607</date> <time>15:45:00</time> <university>Princeton</university> <abstract> <title>On the structure of generalized patent office spaces</title> <content>To be announced.</content> </abstract> </seminar> </seminars> 

The most obvious way to achieve this, I would say, is to use the XSLT stylesheet, which processes the XML and creates some kind of file that the Google calendar can read. I have a website / server where I can host this XSL file so that I can hope that I can only make one download of the desired file.

The XSL sheet is as follows.

(XSL file: "ical.xsl")

 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" encoding="iso-8859-1" media-type="text/calendar"/> <xsl:variable name="crlf">&#13;&#10;</xsl:variable> <xsl:template match="/">BEGIN:VCALENDAR<xsl:value-of select="$crlf"/> CALSCALE:GREGORIAN<xsl:value-of select="$crlf"/> VERSION:2.0<xsl:value-of select="$crlf"/> SEQUENCE:1<xsl:value-of select="$crlf"/> X-WR-TIMEZONE:Europe/Paris<xsl:for-each select="seminars/seminar"><xsl:value-of select="$crlf"/> BEGIN:VEVENT<xsl:value-of select="$crlf"/> LOCATION:<xsl:value-of select="location"/><xsl:value-of select="$crlf"/> DTSTART:<xsl:value-of select="date"/>T154500<xsl:value-of select="$crlf"/> DTEND:<xsl:value-of select="date"/>T164500<xsl:value-of select="$crlf"/> DESCRIPTION:seminar by <xsl:value-of select="speaker"/><xsl:value-of select="$crlf"/> SUMMARY:<xsl:value-of select="abstract/title"/><xsl:value-of select="$crlf"/> END:VEVENT<xsl:value-of select="$crlf"/></xsl:for-each> END:VCALENDAR<xsl:value-of select="$crlf"/> </xsl:template> </xsl:stylesheet> 

This works if I process the XML file, attach it to the iCal file ( xsltproc seminars.xml > mycal.ics ) and import it into any calendar in the Google calendar. The result of mycal.ics as follows:

 BEGIN:VCALENDAR CALSCALE:GREGORIAN VERSION:2.0 SEQUENCE:1 X-WR-TIMEZONE:Europe/Paris BEGIN:VEVENT LOCATION:Zurich DTSTART:20150607T154500 DTEND:20150607T164500 DESCRIPTION:seminar by A. Einstein SUMMARY:On the structure of generalized patent office spaces END:VEVENT 

Now the problem is that (1) Google does not process XML, creating an error while importing, and (2) I'm not sure if this method will automatically β€œcatch changes”, as this will require reloading the XML occasionally,

So, is there a way to get Google (or the web server) to process this file so that it is recognized as an iCal file and update it?

Finally, the small problem is that the source XML has a different XSL file inside. Is there an easy way to make something like a symbolic link on my website into this file or include XML without a header so that I can simply replace the original XSL with mine?

+7
xml xslt csv
source share
1 answer

The simplest solution is probably to create CGI on your web server, which will convert from xml to ical. If your web server is running Linux, then CGI may be as simple as the following file (I called it seminars )

 #!/usr/bin/sh echo Content-type: text/calendar echo /usr/bin/xsltproc ical.xsl seminars.xml 2> /dev/null 

This CGI script is processed by the Bourne shell. This is indicated on the first line. The next 2 lines complete the HTTP header with the media type (mime type) from the physical calendars. The last line is converted using the XSLt transform. Note that errors due to the processing command are ignored (redirected to / dev / null).

Please note that your server must be configured to run CGI. I tested it on Apache 2 and needed

  chmod 755 seminars # make CGI file executable chmod . 711 # close directory to others (suexec) 

I also created the .htacces$ file in the directive to make sure that the seminars script is processed as CGI

  <Files seminars> SetHandler cgi-script </Files> 
+1
source share

All Articles