Parsing XML: SAX, DOM, Expat, or Something Else?

Stefan Behnel stefan_ml at behnel.de
Fri Jan 23 20:38:55 CET 2009


Chris Rebert wrote:
> On Fri, Jan 23, 2009 at 11:19 AM, aha <aquil.abdullah at gmail.com> wrote:
>> I've been charged with developing an XML configuration file format,
>> for one of the applications that my company develops.
>> [...]
>> I am still trying to determine the
>> best XML parser API to use.  I would love to use XPATH, however I face
>> the following restriction:
>>
>> The Python scripts that perform the parsing of the XML configuration
>> file must be compatible with Python Versions 2.2-present.
> 
> ElementTree is in the std lib for Python 2.5+ and has a fairly
> Pythonic API compared to SAX/DOM.
> Docs for it: http://docs.python.org/library/xml.etree.elementtree.html

The downloadable package (version 1.2.x) still works with Python 2.2 (last
I heard, at least). ET also has simple support for XPath-like expressions
(without conditions, that is). Starting to use it now will however allow
you to switch to the mostly compatible lxml.etree package once you decide
to move on to Python 2.3 or later. lxml has full support for XPath (and
XSLT and tons of other goodies).

Stefan



More information about the Python-list mailing list