[XML-SIG] 0.5.1 and 0.6.2

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri, 1 Dec 2000 00:47:39 +0100

> Well, I was using DOM (a file gets processed, then the tree gets
> traversed, needed information obtained, and the result file gets
> dumped).

In that case, it will be difficult to come up with code that works
identical for both versions. In PyXML 0.5, there was a single DOM
implementation; let's call it PyDOM. Instances of Document nodes where
created using a Builder instance.

In PyXML 0.6, there are two DOM implementations: minidom and 4DOM;
minidom is also provided in Python 2. A minidom instance is created
using xml.dom.minidom.parse[String]. A 4DOM instance is created using

Once you have a Document, processing it should be identical between
all those DOM implementations - that is what the DOM standard provides.

Finally, generating back XML varies among implementations. minidom's
Node provides a toxml method; 4DOM offers xml.dom.ext.[Pretty]Print;
PyDOM had xml.dom.writer.XMLWriter and derived classes.

So if you need code that works with both versions, you probably need
to conditionalize, and unify interfaces for your needs:

  import xml.dom.sax_builder
  import xml.dom.writer
  import xml.sax.saxexts
  domversion = "PyDOM"
except ImportError:
  import xml.dom.ext.reader
  domversion = "4DOM"

def build_from_string(str):
  if domversion = "PyDOM":
    builder = xml.dom.sax_builder.SaxBuilder()
    parser = xml.sax.saxexts.make_parser()
    io = StringIO(str)
    return builder.doc
  elif domversion = "4DOM":
    return xml.dom.ext.reader.FromXmlString(str)

Likewise, you could wrap output generation.

Hope this helps,