[Zope-Coders] expat fun & games
Fred L. Drake, Jr.
fred@zope.com
Wed, 13 Feb 2002 09:03:37 -0500
Martijn Faassen writes:
> But on Windows the dir() list (I'm not going to type it all in, try it
> yourself), is different. For instance, StartDoctypeDeclHandler, which
> ParsedXML uses, is missing..
>
> What's up with that? Now going to try to install PyXML 0.7 to see if
> perhaps that fixes it on Windows..
Installing PyXML 0.7 should be fine; it uses Expat 1.95.2, which is
what I recommend. Python 2.1* on Windows uses Expat 1.2, which is
old. Python 2.2* on Windows uses 1.95.2, so that's good too.
The basic issue is that pyexpat is a low-level interface to the
parser; I don't recommend it to application developers. Use SAX or
the DOM instead. Yes, there's a slight performance penalty for the
abstraction layer, but the APIs don't change according to the
underlying Expat version.
It might be interesting to add a SAX2 reader interface directly to
pyexpat; that would certainly help avoid some of the performance
problems associated with using a Python-level SAX driver. Alas, it
would take time to implement and test.
> This is pretty frustrating; portability of Python XML stuff to windows
> shouldn't be this horrible!
You can certainly re-build pyexpat on Windows using the 1.95.2
release, if you have the requisite tools. It shouldn't take more than
a few changes to the project files (can't check right now since I'm
not in Windows-land).
On Unix, the Python installation will use whatever version of the
Expat library is already available, but will not provide one. The API
for the pyexpat module (esp. it's parser object) will depend on the
Expat version for some of the less significant callbacks, but
Parsed XML relies on these for completeness.
Python 2.3* will include Expat 1.95.2 in the box for all platforms, so
the API variation will go away, but that doesn't help pre-2.3
versions. For Parsed XML, I might be able to make it use older
versions of the pyexpat API, but I'm not sure it's worth it (and
certainly won't be unless Jim or Guido say so).
It would be nice to have time to help fix up some of the problems that
are plaguing Parsed XML users (Guido, Jim: hint, hint!).
-Fred
--
Fred L. Drake, Jr. <fdrake at acm.org>
PythonLabs at Zope Corporation