Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

XML Property Lists

In Mac OS X, the preferred way to store property lists is with an XML file called an XML property list or XML plist. These files have the advantages of being human-readable and in the standards-based XML format. The NSArray and NSDictionary classes both have methods for saving themselves as XML plists (descriptionWithLocale:, writeToFile:atomically:), and NSString declares a method to convert XML plists back to objects in memory. CFPropertyList provides functions for converting to and from XML plists, and supports XML as the exclusive method for representing property lists on disk.

XML plists are used extensively throughout Mac OS X. For example, the Finder uses XML plists to store file and directory attributes, and the Cocoa user defaults system uses them to store application preferences.

In general, you should not need to edit XML property lists by hand, but it is useful to understand their structure for design and debugging purposes. Like every XML file, XML plists begin with standard header information, and contain one root object, wrapped with the <plist> document type tag. The <plist> object also contains exactly one object, denoted by one of the tags listed in Table 1.

Table 1  Cocoa and Core Foundation Types with XML Equivalents

Cocoa class

Core Foundation type

XML tag

NSString (java.lang.String)

CFString

<string>

NSNumber (integer)

CFNumber (integer)

<integer>

NSNumber (floating-point)

CFNumber (floating-point)

<real>

NSDate

CFDate

<date>

NSNumber (BOOL YES)

CFBoolean (kCFBooleanTrue)

<true/>

NSNumber (BOOL NO)

CFBoolean (kCFBooleanFalse)

<false/>

NSData

CFData

<data>

NSArray

CFArray

<array>

NSDictionary

CFDictionary

<dict>

Data bytes are base-64 encoded between the <data> and </data> tags.

Graphs of objects are created by nesting the XML tags defined for property lists. When encoding dictionaries, the tag <key> is used for dictionary keys, and one of the other property list tags is used for the key’s value. Here is an example of XML data generated from a property list:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="1.0">
<dict>
    <key>Author</key>
    <string>William Shakespeare</string>
    <key>Lines</key>
    <array>
        <string>It is a tale told by an idiot,</string>
        <string>Full of sound and fury, signifying nothing.</string>
    </array>
    <key>Birthdate</key>
    <integer>1564</integer>
</dict>
</plist>


< Previous PageNext Page > Hide TOC


Last updated: 2006-11-07




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice