XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

The XML in Apple's Keynote

January 07, 2004

Released early in 2003, Keynote is Apple's David versus the Goliath in the presentation software market, Microsoft's PowerPoint. Consumers may find Keynote's slingshot to be an attractive and friendly user-interface in addition to professionally designed themes. But Apple has equipped Keynote with another weapon which developers might find interesting: XML. Keynote uses XML to save presentation documents, opening the door to developers who wish to dynamically create presentations via programs written in any language that sports XML support.

From AppleScript to XML

Whereas PowerPoint uses a binary format to store the information for a presentation, Apple chose to create a publicly documented XML vocabulary to store Keynote presentations, APXL (short for Apple Presentation XML). While XML is used extensively in OS X (Cocoa applications use XML to store application preferences and cross-platform server-side applications such as Tomcat and Cocoon use XML for configuration files), until now, it has never been used by Apple as the sole method to store documents.

The crown of workflow automation on the Mac traditionally belongs to AppleScript, a language that is used to script the Finder (which provides operations that are typically delegated to the operating system) and other applications that provide a dictionary. Essentially, AppleScript provides a high level of interprocess communication; in much the same way that pipelines are used to to pass information between programs in the command-line environment, AppleScript can pass information between applications in a windowed environment. For more information on AppleScript, refer to the AppleScript site or "AppleScript: The Definitive Guide" by Matt Neuburg (O'Reilly & Associates Inc, 2003). But Apple has gone down a different path with Keynote; instead of making the application scriptable, Keynote uses the XML document to facilitate workflow automation.

Keynote Presentation File Structure

Keynote documents are actually directories that contain all the necessary files for the presentation, including:

  • an XML file containing the information for the presentation (such as the slides, graphs, charts, etc.),
  • any other resources required for the presentation, such as images and QuickTime media.

However, the Finder treats these directories, called bundles, as regular directories. This can be seen by using the Terminal application to view the bundle's contents:

Keynote file directory listing
Figure 1: Viewing a Keynote presentation's files in the Finder requires a bit of trickery, whereas the FreeBSD layer treats the presentation as a regular directory.

Every presentation's information is stored in the presentation.apxl file located within the bundle. And because the meat of a presentation is merely an XML file, you now have your entire XML toolbox at your disposal to create presentations. It should be noted that you are free to create presentations on any platform you choose, as Keynote is only necessary to view the presentation and export it to other formats. However, this situation could change in the unlikely event that another presentation program adopts the APXL syntax for their documents.

Understanding APXL

There are essentially three ways to get a grasp on APXL's flavor:

  • download the schema for Keynote presentations, or
  • create a presentation and experiment with its content while viewing the APXL file in a text editor.
  • a combination of the above, using the XML file to understand the basic structure, and then referring to the schema for the fine details.

If you open an APXL file in a text editor, you'll find that the document is divided into 4 branches underneath the presentation root:

  1. presentation metadata, such as the version of Keynote that created this presentation;
  2. the master slide definitions which act as templates for the slides, thereby governing their appearance;
  3. the slides that contain the content of the presentation, typically divided into bullets, charts & graphs, and references to external files;
  4. and the state of the user interface, such as the index of the currently selected slide in the presentation.

Items 1 and 4 in the above list are trivial to create. As for item 3, Apple has created several themes that are included with the software (and it is a relatively trivial process to create your own). While these themes serve as the starting point for presentations created via the Keynote application, they can also serve as a starting point for your own dynamically generated presentations. To save a lot of effort in setting up your presentation, simply copy the master-slide branch to your own DOM tree (or include the events in your SAX stream).

Screenshot of Keynote's theme selection dialog
Figure 2: Keynote's theme selection dialog provides an overview of the included themes.

As for item 3: this is where you'll spend the bulk of your efforts in creating a presentation, as each solution requires unique logic. For example, the markup for data to be displayed in a graph typically looks like:


<array>
  <array>
    <null/>
    <-- the name of the graph -->
    <string>Quarters</string>
  </array>

  <!--
    the following arrays contain the
    information displayed in the graph
  -->
  <array>
    <-- the label of the column-->
    <string>column1</string>
    <-- the value for the column-->
    <string>873</string>
  </array>
  <array>
    <string>column2</string>
    <string>211</string>
  </array>
  <array>
    <string>column3</string>
    <string>416</string>
  </array>
  <-- etc...-->
</array>

It is possible to use SVG or XSL-FO to create your presentation, although they are designed for more general purposes. The main advantage in using Keynote is that the logic embedded in the presentation layer of the application does the heavy-lifting in producing the output; the obvious disadvantage is that you'll need a copy of Keynote in order to present the resulting document to an audience or to export it to another format for distribution, whereas SVG and XSL-FO implementations are typically platform independent and don't require a proprietary application to view the result.

Existing Applications That Incorporate Keynote

There are currently several applications for OS X that leverage Keynote's capabilities: both FileMaker Pro and 4th Dimension's Keynote Builder can now export information contained in a database into a Keynote presentation. However, it is trivial to create a custom application that suits your needs.

A simple Java class that generates Keynote presentations is available here. It uses SAX to read a template presentation, replacing a specific tag (in this case, the <graphFiller/> tag) with information that will populate a graph. It should be noted that the template file cannot be opened in the Keynote application, since the inclusion of the <graphFiller/> tag causes the document to no longer validate against the APXL schema.

Screenshot of presentation created by GraphFiller
Figure 3: The result of executing GraphFiller, a Java class that illustrates how to dynamically populate Keynote presentations using a template.

Resources

Apple is promoting Keynote to developers as a tool to serve as the presentation medium for applications on OS X. There are several resources on the Apple Developer Connection site targeted towards developers who may be considering incorporating Keynote into their applications:

  • technical notes regarding the APXL format, available here and here,
  • a mailing list for developers who are creating Keynote tools,
  • and a sample program that creates a presentation from scratch.


1 to 2 of 2
  1. Omnioutliner
    2004-01-19 07:13:26 David Huston
  2. DocBook Slides
    2004-01-11 12:11:19 Steve Ball
1 to 2 of 2