Both Pages documents and Keynote presentations are bundles. A bundle is a directory containing related resources and is treated as a single object (application, document, and so on) by Mac OS X. The term bundle refers both to the object and to the directory it represents.
Keynote and Pages document bundles contain a compressed XML file that describes the entire document, plus the media files that are used in the document, although certain media assets can be referenced externally.
For Keynote, some media files are actually kept in the theme bundles, which are part of the application. Likewise, media files belonging to Pages’ templates are referenced from the template bundles to help reduce the size of user documents. A user can also choose whether to copy QuickTime movies into the document bundle.
Package Contents
Decompressed Keynote Files
Decompressed Pages Documents
Setting Preferences
To view the contents of a Pages or Keynote file, you can control-click it, and select Show Package Contents from the contextual menu that appears.
A Keynote document bundle contains an index.apxl.gz file containing the compressed XML for the document, a Contents folder that contains only the bundle PkgInfo, and a Thumbs folder, which stores a thumbnail image of each slides (seen in the slide sorter on the left column of the application). Media assets are also saved here.
Likewise, a Pages document bundle contains an index.xml.gz file containing the compressed XML for the document, a Contents folder that contains only the bundle PkgInfo, and a Thumbs folder, which stores thumbnail images of the pages. Media assets are also saved here.
The XML files use standard zlib compression, and may be decompressed by double-clicking the file, or with the gzip command-line tool. The applications can also recognize the files in their uncompressed form (without the .gz extension). Be aware that the compressed version is preferred if both exist in the document bundle.
Note that a Keynote 2.x index file is called index.apxl, while a Pages 1.x index file is specified simply as index.xml.
If you decompress a Keynote document’s index.apxl.gz file and open it in a text editor, you’ll see something similar to what is shown in “Listing 2-3.”
Listing 1-3 Decompressed Keynote XML viewed in a text editor
<key:presentation xmlns:sfa="http://developer.apple.com/namespaces/sfa" xmlns:sf="http://developer.apple.com/namespaces/sf" xmlns:xsi="http://www.w3.org/ 2001/XMLSchema-instance" xmlns:key="http://developer.apple.com/namespaces/ keynote2" sfa:ID="BGShow-0" key:play-mode="interactive" key:kiosk-slide-delay="5" key:kiosk-build-delay="2" key:mode="once" key:version="2004102100"> |
<key:theme-list sfa:ID="NSMutableArray-0"> |
<key:theme sfa:ID="BGTheme-0" key:name="Theme" key:decimal-tab="."> |
<key:size sfa:w="800" sfa:h="600"/> |
<key:stylesheet sfa:ID="SFSStylesheet-0"> |
<sf:styles> |
. |
. |
. |
. |
<key:slide-list> |
<key:slide sfa:ID="BGSlide-6" key:depth="0"> |
<key:ui-state> |
<key:version-history> |
<key:size> |
</key:presentation> |
In every Keynote document, the <key:presentation> element has a number of attributes, including four namespaces that are used throughout the document: (sfa, sf, xsi, and key), and a key:play-mode.
The <key:presentation> elements’ children include <key:theme-list>, <key:slide-list> , <key:ui-state>, <key:version-history>, and <key:size>, as discussed earlier in this chapter.
In the example shown in “Listing 2-4,” you’ll see the partial structure of elements from the beginning of a <key:theme-list> element to the beginning of a child <sf:styles> element.
Listing 1-4 Keynote XML order from theme-list to styles
<key:theme-list sfa:ID="NSMutableArray-0"> |
<key:theme sfa:ID="BGTheme-0" key:name="Theme" key:decimal-tab="."> |
<key:size sfa:w="800" sfa:h="600"/> |
<key:stylesheet sfa:ID="SFSStylesheet-0"> |
<sf:styles> |
. |
. |
. |
Here the <key:theme-list> element has three children: a <key:theme> with a key:name attribute, a <key:size> with attributes specifying the width a sfa:w and the height sfa:h, and a <key:stylesheet>.
If you decompress a Pages document’s index.xml.gz file and open it in a text editor, you’ll see something similar to what is shown in “Listing 2-5” near the bottom of the file.
Listing 1-5 Decompressed Pages XML
<sf:text-storage sf:kind="body" sfa:ID="SFWPStorage-8"> |
<sf:stylesheet-ref sfa:IDREF="SFSStylesheet-1"/> |
<sf:attachments/> |
<sf:footnotes>...</sf:footnotes> |
<sf:text-body> |
<sf:section sf:name="Chapter 1" sf:style="section-style-0"> |
<sf:layout sf:style="layout-style-20"> |
<sf:p sf:style="paragraph-style-32">Main body text.<sf:br/></sf:p> |
<sf:p sf:style="SFWPParagraphStyle-44">Second paragraph with a |
<sf:span sf:style="SFWPCharacterStyle-5">character</sf:span> style and a<sf:tab/>tab.<sf:br/></sf:p> |
<sf:p sf:style="paragraph-style-32"> |
<sf:br/> |
</sf:p> |
. |
. |
. |
</sf:layout> |
</sf:section> |
</sf:text-body> |
</sf:text-storage> |
In this example, the <sf:text-storage> element has an attribute, sf:kind, which specifies that it pertains to the text in the document’s main body.
The <sf:text-storage> element has four children: a <sf:stylesheet-ref>, which is a reference to a style sheet that appears earlier in the document, the <sf:attachment> and <sf:footnotes> elements, and a <sf:text-body> element.
The <sf:text-body> element has one or more child elements: an <sf:section>, which itself has one or more child <sf:layout> elements, which in turn has one or more <sf:p> elements, each of which has a sf:style attribute that specifies the identifiers of the sections, layouts, and paragraphs, respectively, of the first section, layout, and paragraph of the main body text.
Both Pages and Keynote have several preferences you can set that make it easier to work with their XML files:
defaults write com.apple.iWork.Pages SaveCompressionLevel 0 |
defaults write com.apple.iWork.Keynote SaveCompressionLevel 0 |
When the SaveCompressionLevel default is set to 0, the XML file will not be compressed. The normal value is 3.
defaults write com.apple.iWork.Pages FormatXML YES |
defaults write com.apple.iWork.Keynote FormatXML YES |
When the FormatXML default is set to YES, the XML will be written formatted for easier viewing and editing. The normal value is NO.
Last updated: 2005-11-09