Re: normalize in PyXML version hell (was: ...)
Will Partain <[email protected]>
| Newsgroups | gmane.comp.sysutils.ark.devel |
|---|---|
| Message-ID | <[email protected]> |
Harlan, still on the PyXML warpath:
> File "/usr/local/lib/python2.0/site-packages/_xmlplus/dom/minidom.py", line 462, in parse
> return _doparse(pulldom.parse, args, kwargs)
> File "/usr/local/lib/python2.0/site-packages/_xmlplus/dom/minidom.py", line 456, in _doparse
> toktype, rootNode = events.getEvent()
> File "/usr/local/lib/python2.0/site-packages/_xmlplus/dom/pulldom.py", line 171, in getEvent
> buf=self.stream.read(self.bufsize)
> AttributeError: read
Sigh. Well, there comes a time when you have to get out a
big stick and hit it. See if dropping this block into
xmlfile.py does the trick:
try: # should work for 2.0 with PyXML 0.6.2+
import xml.dom.minidom
doc = xml.dom.minidom.parse(filename)
root_elem = doc.documentElement
if not hasattr(root_elem,'normalize'):
# oops... smell 0.6.1 or something....
raise 'bad dom'
except ImportError:
# this is probably something like Python 1.5.2/1.6
# with PyXML 0.5.5.1. Or *something*.
import xml.dom.core
import xml.dom.utils
doc = xml.dom.utils.FileReader().readFile(filename)
root_elem = doc.documentElement
except 'bad dom':
# this ought to be Python 2.0 with PyXML 0.6.1 or
# thereabouts.
import xml.dom.ext.reader.Sax
thing_file = open(filename)
doc = xml.dom.ext.reader.Sax.FromXmlStream(thing_file)
root_elem = doc.documentElement
thing_file.close() # because we're about to reopen it
root_elem.normalize()
Let me know how you get on.
Will