Understanding XML Property Lists
The preferred way to store property lists on OS X and iOS is as 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
NSDictionary classes both have methods for saving themselves as XML plists (for example,
writeToFile:atomically:), and also have methods to convert XML property lists back to objects in memory. CFPropertyList provides functions for converting property lists to and from their XML representation.
Core Foundation supports XML as the exclusive medium for the static representation of property lists on disk. Cocoa allows property lists to be stored on disk as XML property lists, in binary form, and as “old-style” property lists. The old-style property lists can only be read, not written; see Old-Style ASCII Property Lists for further information.
Generally, there is little need to create or edit XML property yourself, but if you do, use Xcode’s built-in property list editor or the Property List Editor application (which is part of the tools package). You should not edit the XML data in a text editor unless you are very familiar with XML syntax and the format of property lists. Moreover, the elements in an XML property list could change in future releases, so keep that in mind.
Even if you don’t edit XML property lists, 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 XML elements listed in Table 2-1.
Graphs of objects are created by nesting the XML elements listed in Table 2-1. When encoding dictionaries, the element
<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">
<string>It is a tale told by an idiot,</string>
<string>Full of sound and fury, signifying nothing.</string>
Note that data bytes are base-64 encoded between the