macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Keynote's XML Connections

by David Miller
11/19/2003

In his article that compares OS X's presentation programs, Ian F. Darwin illustrates that Keynote has what it takes to compete with PowerPoint, both in terms of its ease of use and feature set.

However, Keynote goes one step further than PowerPoint by making it easy to dynamically create presentations from within other applications. Traditionally this would fall into the realm of AppleScript. But with Keynote, Apple has gone down a different path.

Opening Tag: AppleScripts and Oranges

AppleScript serves as the glue between applications on the Mac by providing a channel to transfer information from one application to another (e.g., take information out of a FileMaker database and insert it into an HTML document via BBEdit). In order to take advantage of AppleScript, an application must provide a dictionary that tells the scriptable architecture of OS X what commands are supported by the application (for example, a web browser will use the getURL command to open a web page). However, if an application doesn't provide a dictionary, then it can't be scripted.

In a similar vein, XML serves as the glue between applications that run on a variety of platforms: everything from high-end web and application servers to hand-held PDAs. However, there is a large difference between the two: AppleScript is a programming language that is used in scripts that are interpreted by the operating system and then executed, while XML defines how information is stored in a file. This XML file can then be passed between applications to transfer the information from one system to another. For a more detailed introduction to the basics of XML, refer to Learning XML, 2nd Edition by Erik T. Ray (O'Reilly & Associates, 2003).

XML En Vogue

Related Reading

Learning XML
By Erik T. Ray

There are a variety of reasons why XML has become so popular in recent years, one of the biggest being that it provides standard methods to store and retrieve information, no matter what that information may be. In theory, XML can be used to describe almost any type of information imaginable, including:

  • SVG for vector graphics,
  • RSS for syndication,
  • XML-RPC for distributed computing,
  • XHTML for hypertext documents,
  • and countless other types of information.

But how are we to understand the difference in structure between an XML document that holds data for a vector graphics image, and one that is used to describe a web page? Documents that are simple in nature can be understood by inspecting them. Anyone with a basic familiarity with XHTML can inspect the source of a webpage to understand how it is built. However, how are we to understand how more complicated documents, such as Keynote presentations, are structured?

The answer to that question lies in XML Schema. A schema is simply an XML document that describes how another XML document can be structured. Since the information required to describe a vector image is different from the information required to describe a hypertext document, the two documents will require unique structures for their information, and hence, they will also require unique schema. Any document that conforms to its schema is considered valid, while any XML document that doesn't validate against its schema is pretty much useless (it's like having a CSV file with commas in the wrong places).

To Infinity And Beyond: Keynote and XML

In addition to the abbreviated list of XML applications given above, developers are free to create their own XML syntax to suit their needs. In order for anyone else to understand how the document can be structured, the schema must be made available. Let's say developer X wants to create an XML representation for his recipe collection. In order for developer Y to understand the structure that X has settled on, she will need the schema for the document.

And this is what precisely what Apple has done with Keynote's presentations: they've created an XML syntax, APXL (short for Apple Presentation XmL), and made its schema publicly available on the Apple Developer Connection site. So with Keynote's release, Apple is making waves for two reasons:

  • Apple is entering into direct competition with another one of Microsoft's staple applications: PowerPoint. And with Safari trouncing Internet Explorer on OS X, Apple is becoming increasingly independent from Microsoft in providing the applications required for its operating system to be considered viable in a professional environment.
  • Keynote is Apple's first application that uses XML to save a document's data.

The second point has long been considered the Holy Grail for XML; while it has gained momentum in web and enterprise applications, it has never been utilized as the file format for documents in a mainstream desktop application. Why? Possibly the biggest reason is that by using a plain text file format for documents, people are free to edit the document without using the original application. While this may seem insignificant, it also means that other applications can also read and write the files, and this is exactly what Apple has chosen to do with Keynote presentations. Contrast this situation with MS Office, where Microsoft encourages you to use its applications to edit Office documents.

Brave New World: XML Instead of AppleScript

At this point, you might be wondering how it all ties together: AppleScript, XML, and Keynote. Traditionally, if you want to create an automated workflow on the Mac (such as the one documented in this article by Mac DevCenter's editor, Derrick Story), you'll need at least one application that can be controlled with AppleScript. Well, guess what? If you try opening Keynote's AppleScript dictionary in Script Editor, you'll find out that there is no dictionary, which makes it pretty much impossible to create a presentation via AppleScript. But don't lose all hope yet: Keynote's XML file format fills the hole. By editing an XML document, you can actually work with a Keynote presentation from your own application. Try working with a PowerPoint document in something other than PowerPoint, and you'll see what a difference Keynote's method of document storage makes.

Integrating Keynote With Applications

FileMaker Pro

The Mac's friendly neighbourhood database, FileMaker includes XML support in the latest version. By doing so, it is now possible to transform the information stored in a database into a variety of XML flavors. And, yes, Keynote presentations are now included in that list. The tool can be downloaded from here.

A sample Keynote presentation created by FileMaker Pro
A sample Keynote presentation created by FileMaker Pro



4-D Keynote Builder

A perfect example of how Keynote can be used as a presentation medium for other applications is 4th Dimension's Keynote Builder. By querying a database based on a client's preferences for a house, the application produces a presentation that will contain one slide for each house that matches the necessary criteria. In turn, each slide will contain a photo of the house along with other pertinent information. From this point, the realtor can export the presentation (to PDF, QuickTime, or PowerPoint) or present the slideshow to the client. A sample slide is shown below:

A sample slide from 4D's Keynote Builder
A sample slide from 4D's Keynote Builder



A Custom Solution

However, we're not limited to using existing solutions to dynamically generate Keynote presentations. The tools necessary to create your own workflow are freely available:

  1. A compiler and runtime system (or an interpreter for the scripters in the audience) for your language of choice,
  2. an XML parser,
  3. and an understanding of Apple's APXL schema, which is documented here.

You'll notice that an actual copy of the Keynote application is not listed; you can create a Keynote presentation on virtually any computer, since essentially all that you are doing is working with plain text files. However, you'll need a copy of Keynote in order to work with the resulting presentations in any useful matter, whether that be printing, viewing, or presenting them to an audience.

What You'll Need to Know

Keynote documents are actually stored as directories that contain all of the files require by the presentation; these directories are called "bundles", and the Finder treats each bundle as a single file (this is identical to Cocoa applications, which wrap directories around all of the necessary components for an application). By right-clicking on a document and then selecting "Show Package Contents", the Finder will show all of the files that make up the presentation. Alternatively, you can use Terminal and ls to view the files, since OS X's BSD foundation treats Keynote documents as regular directories).

Inspecting the contents of a Keynote presentation
Inspecting the contents of a Keynote presentation

The presentation.apxl file is the XML document that stores all of the information for a presentation, including all the slides, bullets, headings, charts and graphs, while the other files are media that is used in the presentation, such as images, movies, or other multimedia elements. If you open the presentation.apxl file in a text editor, you'll notice that it's more than a little unwieldy. Generating all of that markup from scratch is not practical for the purposes of this tutorial, so we'll take a shortcut and create a template presentation to create the bulk of the XML, and simply fill in the necessary blanks with our code.

Pages: 1, 2

Next Pagearrow