This is a Python parser class for Apple’s Property Lists XML.
A Property Lists is a data representation used in Apple’s Mac OS X as a convenient way to store standard object types, such as string, number, boolean, and container objects (dictionary and array). Either datetime and binary data are also supported.
You can run self-contained test, and parse any property list by running plist_parser.py
. For example, parsing iTunes Liberary on your mac:
% python ./plist_parser.py ~/"Music/iTunes/iTunes Music Library.xml"
This project provides two classes (in plist_parser.py
file):
- XmlPropertyListParser
- PropertyListParseError
You can use these classes by importing:
from plist_parser import XmlPropertyListParser, PropertyListParseError
or copy and paste on your code (Feel free to do it).
To parse a property list xml. First, instantiates XmlPropertyListParser
:
>>> parser = XmlPropertyListParser()
Second, invoke parse
method with XML contents or file-like object.
>>> parser.parse("""
<plist version="1.0">
<dict>
<key>Python</key>
<string>.py</string>
</dict>
</plist>
""")
{'Python': '.py'}
or
stream = open(...)
try:
plist = parser.parse(stream)
finally:
stream.close()
You need no third-party library other than Python 2.4 or higher.
The XmlPropertyListParser
class internally uses builtin libraries (listed below) to parse XML file.
xml.sax
- or The C implementation of
xml.etree
if available (xml.etree
is new in Python 2.5)
- plistlib Python 2.6 shipped with plistlib module. This module was previously only available in the Mac-specific library
Copyright © 2008 Takanori Ishikawa <takanori.ishikawa@gmail.com>, All rights reserved.
The MIT license. See the LICENSE
file for more details.