[XML-SIG] python SAX API

Alexandre Fayolle Alexandre.Fayolle@logilab.fr
Fri, 16 Nov 2001 13:43:22 +0100 (CET)


On 16 Nov 2001, Lars Marius Garshol wrote:

> One of the reasons to split startElement and startElementNS was to
> make things easier for newcomers to the API. They could then get
> started with ordinary XML programming with a relatively simple API,
> and not have to worry about the complexities of namespaces until they
> actually needed them. Having startElementNS as the default would
> negate that benefit.

My main concern is that this means python is providing a canada dried
version of SAX: it's called SAX, it looks like SAX, it tastes a bit like
SAX, but it's not SAX. I've learnt the Java SAX API, and I'm fairly
familiar with it. My main use of XML and Python so far was DOM (esp.
4DOM), so I didn't look at python's SAX. Now I have to, and each time I
do, I get nasty surprises. The startElementNS is one. The namespace
feature is another one. Different parsers not implementing the same spec
is yet another one. Different parsers representing empty nsuri with empty
strings or None is another major pain.

I personnally don't really care what the final choice is, as long as it is
written in big red flashing letters in the python library reference guide,
and I know that any python that calls itself a sax parser will behave
correctly. Now, if we are going to change the SAX API substancially, I'd
say that SAX is a poor choice of a name, because people used to the real
things will get the impression that they do not need to read the Python
doc, and will get bitten when:

 * the startElement callback generates an exception because it gets called
with the wrong number of arguments

 * the startElement callback renamed startElementNS is not called
because they did not set the feature.

 * the startElementNS callback generates an exception because it is one
again called with the wrong number of arguments. 

At that point, they will have read the python sax documentation (and will
have ROTFLed when seeing the reference to the Java SAX API website), and
they'll be able to fix things, and they'll presumably have noticed that
the prototype of the characters() callback is different. However, in the
process, they'll have gotten a very messy impression of the XML support in
Python.

Sorry for expressing myself on the topic so late in the developement
process.

Alexandre Fayolle
-- 
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
Narval, the first software agent available as free software (GPL).