This is a Clojure library to parse the Property List (.plist) files that are ubiquitous on Mac OS X.
The library has one public function, parse-plist
, which takes as input a File, an InputStream, or a String naming a URI to read for the plist data. (parse-plist
just passes its argument to clojure.xml/parse
, so any source usable with that function will work with parse-plist
.) The function returns a native Clojure data structure corresponding to the plist data, according to the following table:
plist tag | Clojure equivalent |
---|---|
array | vector |
data | byte[] |
date | Joda DateTime object |
dict | hash map |
false | false |
integer | Long |
real | Double |
string | string |
true | true |
(use 'com.github.bdesham.clj-plist)
(parse-plist (java.io.File. "MyPropertyList.plist"))
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>String example</key>
<string>This is just some uninteresting text</string>
<key>Array example</key>
<array>
<integer>2</integer>
<real>3.14159</real>
</array>
<key>Boolean example</key>
<true/>
<key>Date example</key>
<date>1969-07-20T07:56:00Z</date>
<key>Data example</key>
<data>YWJjZGVmZw==</data>
</dict>
</plist>
{"Array example" [2 3.14159],
"Boolean example" true,
"Data example" #<byte[] [B@3ea86d12>,
"Date example" #<DateTime 1969-07-20T02:56:00.000-05:00>,
"String example" "This is just some uninteresting text"}
This library is no longer under active development. Pull requests are still welcome.
The entire plist is sucked into memory at once, so there’s a relatively low limit on the size of the plist that can be loaded. (Trying to import my “iTunes Music Library.xml”, which is 16.2 MiB, causes a heap overflow on my system with the default Java memory limits.) Some sort of lazy loading would fix this.
Binary plist files are not supported (see issue 1). In the meantime, you can use plutil
on OS X to convert binary plist files to XML plist files via /usr/bin/plutil -convert xml1 -o output.plist input.plist
.
For more information on plist files, see the Apple man page for property list files.
keyword-fn
function to be applied to <key>
elements (thanks Ben Cook!)Copyright © 2011–2016 Benjamin D. Esham.
This project is distributed under the Eclipse Public License, the same as that used by Clojure. A copy of the license is included as “epl-v10.html” in this distribution.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close