Difference between revisions of "Property list"
(→dict: Removed information that’s true in OS X but false in GNUstep.) |
(Cleanup and corrections.) |
||
Line 1: | Line 1: | ||
− | [[Image:plist-XML-ASCII-ill.png|thumb|right|300px|the plist formats, XML and | + | [[Image:plist-XML-ASCII-ill.png|thumb|right|300px|the plist formats, XML and OpenStep]] |
− | + | A '''property list''', or '''plist''' for short, is data structured in a standardized way, used by Oolite for a wide variety of configuration files. The concept originates with [http://en.wikipedia.org/wiki/OpenStep OpenStep], the specification on which the Cocoa and GNUstep programming libraries Oolite uses are based. | |
− | |||
− | + | == Formats == | |
+ | A property list is an abstract structure which can be represented files using at least five different formats. Since Oolite uses two different implementations of property list support, one on Mac OS X and another on other platforms, it can’t consistently read all these formats. | ||
− | + | Two formats are recommended for Oolite: the traditional [http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/Articles/OldStylePListsConcept.html OpenStep format], which is easy to read, and the [http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/Articles/XMLPListsConcept.html XML format], which is more flexible. The other formats are Apple binary format (which can be read by both implementations, but is not human-readable), and the GNUstep text and binary formats, which are not supported under Mac OS X. | |
+ | While the OpenStep format does not support all the data types used by Oolite – specifically, it does not support [[#integer|integers]], [[#real|reals]] or [[#boolean|booleans]] – Oolite can in most cases automatically convert [[#string|strings]] to these types starting with Oolite 1.69. (If you find an exception, please report it.) As such, the types can be used interchangeably. In prior versions of Oolite, some types, especially booleans, could not be converted automatically, so XML format was required for some property lists. | ||
− | |||
− | |||
+ | == Data types == | ||
+ | The rest of this page describes the types of property list element used by Oolite, and how they are represented in OpenStep and XML format property lists. It does not cover all property list content types or file formats and is not a general-purpose reference to property lists. | ||
− | |||
− | |||
+ | === string === | ||
+ | A string is a block of text. In OpenStep format plists, this is surrounded by straight double quotation marks, with “<code>\</code>” being used to escape quotation marks within the string: <code>"a string with a \"quotation\" and a <tag>"</code>. OpenStep format plists also allow single-word strings to be used without quotation marks when this is unambiguous. However, the definition of “unambiguous” differs between Mac OS X and GNUstep, so this usage is not recommended except for numbers. In XML format, it is surrounded by <code><string></code> tags, escaping contents with XML entities: <code><string>a string with a &quot;quotation&quot; and a &lt;tag&gt;</string></code>. | ||
− | |||
− | |||
+ | === integer === | ||
+ | An integer is a whole number. In OpenStep format plists, an integer is a string whose contents happen to be digits (and optionally a minus sign), and may be unquoted: <code>-12345</code>. In XML format, it is surrounded by <code><integer></code> tags: <code><integer>-12345</integer></code>. | ||
− | |||
− | |||
+ | === real === | ||
+ | A real is a number with a fractional part. In OpenStep format plists, reals are again written as unquoted strings: <code>42.123</code>. In XML format, reals are surrounded by <real> tags: <code><real>42.123</real></code>. Large reals can be expressed in scientific notation: <code>1.35e+20</code> means 1.35 × 10<small><sup>20</sup></small>. Integers and reals are mostly interchangeable in Oolite. | ||
− | |||
− | |||
+ | === boolean === | ||
+ | A boolean is either of the values ''true'' or ''false''. In XML format, the tags <code><true/></code> and <code><false/></code> can be used. OpenStep format does not support booleans. However, as of Oolite 1.69, a number of different methods can be used to represent them: any of the strings <code>"true"</code>, <code>"yes"</code> or <code>"on"</code> may be used to represent ''true'', and any of the strings <code>"false"</code>, <code>"no"</code> or <code>"off"</code> may be used to represent ''false''. Additionally, the number 0 is interpreted as ''false'' and any other number as ''true'' (but see [[#fuzzy boolean|fuzzy boolean]] below). The recommended form is to use <code>"yes"</code> and <code>"no"</code>. | ||
− | + | Previous versions of this page indicated that numbers could be used as booleans in OpenStep-format property lists in any version of Oolite. This is incorrect and such usage will not work with versions prior to 1.69. | |
− | |||
− | |||
− | + | === fuzzy boolean === | |
+ | A fuzzy boolean isn't really a property list type; rather, it's a special usage defined by Oolite. If a fuzzy boolean is expected, and a number is encountered, it is treated as a probability between 0 and 1. For instance, if a value of 0.5 is used, it will be treated as ''true'' half the time, and ''false'' the other half. Values other than numbers are treated like [[#boolean|booleans]]. | ||
− | |||
− | == | + | === array === |
− | Both formats can also contain comments, which are ignored by the program but are useful to human readers. In | + | An array is an ordered list of objects. In OpenStep format, it is contained in parentheses, with items separated by commas: <code>(0, two, "three and a half", yes)</code>. In XML format, it is contained in <code><array></code> tags: <code><array><integer>0</integer> <true/> <string>two</string> <string>three and a half</string> <true/></array></code>. |
+ | |||
+ | |||
+ | === dictionary === | ||
+ | Dictionaries are the most complex type. The consist of key/value pairs – each pair consists of a key, which is always a string, and a value, which can be any type, including other dictionaries. Each key must be unique, and the order of pairs is not significant. | ||
+ | |||
+ | In OpenStep format, dictionaries are contained in braces, with key and value separated by <code>=</code> signs and pairs separated by semicolons: <code>{length = 42; width = 36.5; "long name" = "this is a thing with a really quite long name"; attributes = (hairy, muscular);}</code>. | ||
+ | |||
+ | In XML format, dictionaries are contained in <code><dict></code> tags, with keys specified by <code><key></code> tags and immediately followed by values with whatever tag is appropriate for the value type: <code><dict><key>length</key><integer>42</integer> <key>width><real>36.5</real> <key>long name</key><string>this is a thing with a really quite long name</string> <key>attributes</key><array><string>hairy</string><string>muscular</string><array></dict></code>. | ||
+ | |||
+ | |||
+ | |||
+ | == Root element == | ||
+ | Every property list has a single value as its root. Typically this is a dictionary. In XML format, the root value must be surrounded by <code><plist></code> tags in addition to its normal type tag: <code><plist><dictionary><key>green</key><array><integer>0</integer><integer>1</integer><integer>0</integer></array></dictionary></plist></code> (OpenStep equivalent: <code>{ green = (0, 1, 0); }</code>). | ||
+ | |||
+ | Under Mac OS X, if the root element of an OpenStep-format property list is a dictionary, it does not have to be surrounded by braces. However, ''this does not work under GNUstep'', so those creating property lists on Macs must be careful. In particular, OpenStep-format property lists exported by Property List Editor may not work under GNUstep. | ||
+ | |||
+ | |||
+ | == Comments == | ||
+ | Both formats can also contain comments, which are ignored by the program but are useful to human readers. In OpenStep format, these can either start with “<code>//</code>” and continue to the end of the line, or start with “<code>/*</code>” and end with “<code>*/</code>”. In XML, they start with “<code><!--</code>” and end with “<code>--></code>” (and must not contain “<code>--</code>” anywhere else in the comment). | ||
Examples: | Examples: | ||
− | + | /* this line is a comment in OpenStep format */ | |
+ | // this line is also a comment in OpenStep format | ||
− | <nowiki> | + | <nowiki><!-- this line is a comment in XML --></nowiki> |
− | ==XML Preamble== | + | == XML Preamble == |
XML plists also need a standard header, which looks like this: | XML plists also need a standard header, which looks like this: | ||
− | + | <?xml version="1.0" encoding="UTF-8"?> | |
− | + | <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "<nowiki>http://www.apple.com/DTDs/PropertyList-1.0.dtd</nowiki>"> | |
+ | |||
+ | |||
+ | == Real-world Example == | ||
+ | The following is a shortened version of Oolite’s built-in ''[[equipment.plist]]'', in both OpenStep and XML formats. | ||
+ | |||
+ | === OpenStep === | ||
+ | ( | ||
+ | ( | ||
+ | 1, 300, "Missile", "EQ_MISSILE", | ||
+ | "Faulcon de Lacy HM3 homing missile, fast and accurate when used in conjunction with standard targetting scanners.", | ||
+ | { | ||
+ | available_to_all = "yes"; | ||
+ | } | ||
+ | ), | ||
+ | ( | ||
+ | 7, 9000, "Energy Bomb", "EQ_ENERGY_BOMB", | ||
+ | "A one-shot super-weapon capable of destroying all small craft within range." | ||
+ | ) | ||
+ | ) | ||
+ | |||
+ | |||
+ | === XML === | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" <nowiki>"http://www.apple.com/DTDs/PropertyList-1.0.dtd"</nowiki>> | ||
+ | <plist version="1.0"> | ||
+ | <array> | ||
+ | <array> | ||
+ | <integer>1</integer> | ||
+ | <integer>300</integer> | ||
+ | <string>Missile</string> | ||
+ | <string>EQ_MISSILE</string> | ||
+ | <string>Faulcon de Lacy HM3 homing missile, fast and accurate when used in conjunction with | ||
+ | standard targetting scanners.</string> | ||
+ | <dict> | ||
+ | <key>available_to_all</key> | ||
+ | <true/> | ||
+ | </dict> | ||
+ | </array> | ||
+ | <array> | ||
+ | <integer>7</integer> | ||
+ | <integer>9000</integer> | ||
+ | <string>Energy Bomb</string> | ||
+ | <string>EQ_ENERGY_BOMB</string> | ||
+ | <string>A one-shot super-weapon capable of destroying all small craft within range.</string> | ||
+ | </array> | ||
+ | </array> | ||
+ | </plist> | ||
Revision as of 10:54, 10 July 2007
A property list, or plist for short, is data structured in a standardized way, used by Oolite for a wide variety of configuration files. The concept originates with OpenStep, the specification on which the Cocoa and GNUstep programming libraries Oolite uses are based.
Contents
Formats
A property list is an abstract structure which can be represented files using at least five different formats. Since Oolite uses two different implementations of property list support, one on Mac OS X and another on other platforms, it can’t consistently read all these formats.
Two formats are recommended for Oolite: the traditional OpenStep format, which is easy to read, and the XML format, which is more flexible. The other formats are Apple binary format (which can be read by both implementations, but is not human-readable), and the GNUstep text and binary formats, which are not supported under Mac OS X.
While the OpenStep format does not support all the data types used by Oolite – specifically, it does not support integers, reals or booleans – Oolite can in most cases automatically convert strings to these types starting with Oolite 1.69. (If you find an exception, please report it.) As such, the types can be used interchangeably. In prior versions of Oolite, some types, especially booleans, could not be converted automatically, so XML format was required for some property lists.
Data types
The rest of this page describes the types of property list element used by Oolite, and how they are represented in OpenStep and XML format property lists. It does not cover all property list content types or file formats and is not a general-purpose reference to property lists.
string
A string is a block of text. In OpenStep format plists, this is surrounded by straight double quotation marks, with “\
” being used to escape quotation marks within the string: "a string with a \"quotation\" and a <tag>"
. OpenStep format plists also allow single-word strings to be used without quotation marks when this is unambiguous. However, the definition of “unambiguous” differs between Mac OS X and GNUstep, so this usage is not recommended except for numbers. In XML format, it is surrounded by <string>
tags, escaping contents with XML entities: <string>a string with a "quotation" and a <tag></string>
.
integer
An integer is a whole number. In OpenStep format plists, an integer is a string whose contents happen to be digits (and optionally a minus sign), and may be unquoted: -12345
. In XML format, it is surrounded by <integer>
tags: <integer>-12345</integer>
.
real
A real is a number with a fractional part. In OpenStep format plists, reals are again written as unquoted strings: 42.123
. In XML format, reals are surrounded by <real> tags: <real>42.123</real>
. Large reals can be expressed in scientific notation: 1.35e+20
means 1.35 × 1020. Integers and reals are mostly interchangeable in Oolite.
boolean
A boolean is either of the values true or false. In XML format, the tags <true/>
and <false/>
can be used. OpenStep format does not support booleans. However, as of Oolite 1.69, a number of different methods can be used to represent them: any of the strings "true"
, "yes"
or "on"
may be used to represent true, and any of the strings "false"
, "no"
or "off"
may be used to represent false. Additionally, the number 0 is interpreted as false and any other number as true (but see fuzzy boolean below). The recommended form is to use "yes"
and "no"
.
Previous versions of this page indicated that numbers could be used as booleans in OpenStep-format property lists in any version of Oolite. This is incorrect and such usage will not work with versions prior to 1.69.
fuzzy boolean
A fuzzy boolean isn't really a property list type; rather, it's a special usage defined by Oolite. If a fuzzy boolean is expected, and a number is encountered, it is treated as a probability between 0 and 1. For instance, if a value of 0.5 is used, it will be treated as true half the time, and false the other half. Values other than numbers are treated like booleans.
array
An array is an ordered list of objects. In OpenStep format, it is contained in parentheses, with items separated by commas: (0, two, "three and a half", yes)
. In XML format, it is contained in <array>
tags: <array><integer>0</integer> <true/> <string>two</string> <string>three and a half</string> <true/></array>
.
dictionary
Dictionaries are the most complex type. The consist of key/value pairs – each pair consists of a key, which is always a string, and a value, which can be any type, including other dictionaries. Each key must be unique, and the order of pairs is not significant.
In OpenStep format, dictionaries are contained in braces, with key and value separated by =
signs and pairs separated by semicolons: {length = 42; width = 36.5; "long name" = "this is a thing with a really quite long name"; attributes = (hairy, muscular);}
.
In XML format, dictionaries are contained in <dict>
tags, with keys specified by <key>
tags and immediately followed by values with whatever tag is appropriate for the value type: <dict><key>length</key><integer>42</integer> <key>width><real>36.5</real> <key>long name</key><string>this is a thing with a really quite long name</string> <key>attributes</key><array><string>hairy</string><string>muscular</string><array></dict>
.
Root element
Every property list has a single value as its root. Typically this is a dictionary. In XML format, the root value must be surrounded by <plist>
tags in addition to its normal type tag: <plist><dictionary><key>green</key><array><integer>0</integer><integer>1</integer><integer>0</integer></array></dictionary></plist>
(OpenStep equivalent: { green = (0, 1, 0); }
).
Under Mac OS X, if the root element of an OpenStep-format property list is a dictionary, it does not have to be surrounded by braces. However, this does not work under GNUstep, so those creating property lists on Macs must be careful. In particular, OpenStep-format property lists exported by Property List Editor may not work under GNUstep.
Comments
Both formats can also contain comments, which are ignored by the program but are useful to human readers. In OpenStep format, these can either start with “//
” and continue to the end of the line, or start with “/*
” and end with “*/
”. In XML, they start with “<!--
” and end with “-->
” (and must not contain “--
” anywhere else in the comment).
Examples:
/* this line is a comment in OpenStep format */ // this line is also a comment in OpenStep format
<!-- this line is a comment in XML -->
XML Preamble
XML plists also need a standard header, which looks like this:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Real-world Example
The following is a shortened version of Oolite’s built-in equipment.plist, in both OpenStep and XML formats.
OpenStep
( ( 1, 300, "Missile", "EQ_MISSILE", "Faulcon de Lacy HM3 homing missile, fast and accurate when used in conjunction with standard targetting scanners.", { available_to_all = "yes"; } ), ( 7, 9000, "Energy Bomb", "EQ_ENERGY_BOMB", "A one-shot super-weapon capable of destroying all small craft within range." ) )
XML
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <array> <integer>1</integer> <integer>300</integer> <string>Missile</string> <string>EQ_MISSILE</string> <string>Faulcon de Lacy HM3 homing missile, fast and accurate when used in conjunction with standard targetting scanners.</string> <dict> <key>available_to_all</key> <true/> </dict> </array> <array> <integer>7</integer> <integer>9000</integer> <string>Energy Bomb</string> <string>EQ_ENERGY_BOMB</string> <string>A one-shot super-weapon capable of destroying all small craft within range.</string> </array> </array> </plist>