[XML-SIG] Uniform interface with Python 2.0

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri, 8 Sep 2000 08:23:31 +0200

I just noticed that it appears to be very difficult to write code that
works both with the Python 2.0 XML package and with the PyXML CVS code.

For example, in CVS, to find create a SAX parser, you do

import xml.sax.saxexts
p = xml.sax.saxexts.make_parser()

In Python 2.0, saxexts is not supported. Instead, you have to know
that the expatreader is there, so you write

import xml.sax.expatreader
p = xml.sax.expatreader.ExpatParser()

That, in turn, won't work in PyXML, as it does not have the
expatreader module.

Alternatively, in Python 2.0, you can write

import xml.sax
xml.sax.parse(file, MyHandler())

Again, that won't work in PyXML: xml.sax does not have the parse

Same goes for dom. To create a DOM tree with the current CVS, you

from xml.dom.ext.reader import Sax
doc = Sax.FromXmlStream(file)

That won't work with Python 2. Instead, there you write

import xml.dom.minidom
doc = xml.dom.minidom.parse(file)

Is there hope that there can be a common API that works with both
Python 2.0 and PyXML?