Events-Client Side XML Example


The following code is for example only. It is up to the web developer to determine how he/she wants to handle the XML data.
This software is provided "as is", without warranty of any kind, express or implied. In no event shall Evanced Solutions be held liable 
for any direct, indirect, incidental, special or consequential damages arising out of the use of or inability to use this software. 
Evanced Solutions is not obligated to support the code due to the various ways XML is handled between browsers.

Events - Client Side XML example

This example shows how JavaScript can be used to display a window of events on your library's homepage, using the XML feed from the calendar software.

To run this example you will need to copy the 3 included files into a web accessible folder on your web server.

   eventsxml.html --> Example Web page used to display a window of events.
   eventsxml.xsl --> Style Sheet formatting file for XML data.
   getxml.asp --> Server-side page for obtaining the XML data and sending it to the HTML page.

Editing the XSL file is beyond the scope of this example, but many resources can be found on the internet by doing a search on the tags "XSL XML tutorial".

Editing the JavaScript in the HTML file is beyond the scope of this example, but many resources can be found on the internet by doing a search on the tags "JavaScript tutorial".

Editing the ASP file is beyond the scope of this example. If your server is not running ASP you may need to translate this page into server-side script that performs a similar function.


To make this example work properly you will need to edit 4 path variables. The first 3 are in the HTML file. Do a search on the word "REPLACE" to find the 3 locations.

<script type="text/javascript" src="http://host.evanced.info/lib/common/zxml.js"></script>

This is a reference to a file included with all Event Calendar installations. If your installation is hosted your path will look something like this:

http://host.evanced.info/YOURLIBRARYNAME/lib/common/zxml.js
var xmlcalendarURL="getxml.asp"

This file should reside on the same server as the "eventsxml.html" page. A hard-coded path is not necessary if this file resides in the same folder as the HTML file.

var xslcalendarURL="eventsxml.xsl"

This is your XSL formatting file. A default version of this file is included with this example. Your path to this file will probably be something like:

www.YOURLIBRARYWEBSITE.org/WEBFOLDER/eventsxml.xsl

Unless it is located in the same folder as the HTML file and will not need a path.

xmlpath="http://host.evanced.info/lib/eventsxml.asp?dm=xml&lib=all&alltime=1&nd=14"

This is a link to the XML feed from your calendar system. The example is a link to our training site. If your installation is hosted your path will look something like this:

http://host.evanced.info/YOURLIBRARYNAME/lib/eventsxml.asp

URL switches can be added to this link to specify the data you want returned from this link. In this example are:

   dm=xml  - Format of the returned data
   lib=all  - Use data from all branches
   alltime=1 - Use data from all day
   nd=14  - Use 14 days worth of data

The ASP file is used to perform a server side request for the XML data. if your server does not support ASP you will need to translate the ASP code into a server-side script that is support by your server. The basic concept is: the client HTML page cannot obtain the XML data directly from a different domain (causes an Access Denied error). This server-side ASP file can obtain the data and pass it to the HTML file as a string.

You will need to remove the comments from the beginning of the getxml.asp file. Since the result of this file should be XML, having a comment at the beginning will cause it to not look like XML data. Remove everything down to, but not including the "<%@ LANGUAGE="VBScript"%>"

Once the HTML and ASP file are edited with your path information, you will be able to open the HTML file in a web browser and see how the XML feed can be displayed in a simple table.

Double-clicking the file may open the file but it will also generate an ActiveX error in your browser. To properly test you should enter the URL to the HTML file in a browser window. This will eliminate the error and display the page properly.

To incorporate this into your site you will need to:
1. Modify the 'eventsxml.xsl' file to use the styles of your website.
2. Copy the javascript code from the example and include it on your website.
3. Use the "displayEvents()" function to do the work.

Download the example files here: https://s3.amazonaws.com/static.evanced.info/Examples/Events_Client_side_XML.zip


Custom Fields

Article ID: 78
Created On: Tue, Sep 27, 2011 at 2:40 PM
Last Updated On: Fri, Nov 21, 2014 at 11:23 AM

Online URL: https://kb.demcosoftware.com/article.php?id=78