[XML-SIG] dom building, sax, and namespaces

Andrew Dalke dalke@acm.org
Wed, 23 Jan 2002 09:21:20 -0700


Sylvain Thenault:
> the namespace declaration should be included in your generated events. I
> guess that's why you can't access the namespaced elements via XPath (I
> don't why pulldom.SAX2DOM doesn't complain, but it should) 

I retract that statement.  It does complain.

>>> from xml.dom import pulldom
>>>
>>> builder = pulldom.SAX2DOM()
>>> builder.startDocument()
>>> builder.startElement('bioformat:dataset',
...              {'xmlns:bioformat': 'http://biopython.org/bioformat'})
Traceback (most recent call last):
  File "<stdin>", line 2, in ?
  File "/usr/local/lib/python2.2/site-packages/_xmlplus/dom/pulldom.py",
line 295,
in startElement
    PullDOM.startElement(self, name, attrs)
  File "/usr/local/lib/python2.2/site-packages/_xmlplus/dom/pulldom.py",
line 122,
in startElement
    node = self.buildDocument(None, name)
  File "/usr/local/lib/python2.2/site-packages/_xmlplus/dom/pulldom.py",
line 173,
in buildDocument
    node = self.documentFactory.createDocument(uri, tagname, None)
  File "/usr/local/lib/python2.2/site-packages/_xmlplus/dom/minidom.py",
line 812,
in createDocument
    raise xml.dom.NamespaceErr(
xml.dom.NamespaceErr: illegal use of prefix without namespaces


Is there some way I can build a proper namespace'd DOM without having
the parser support feature_namespaces?  Some sort of adapter, perhaps?
I couldn't find such in the codebase.  I did find code as in

   sax/drivers2/drv_xmlproc.py 

which I think I could use to write such an adapter, but it would
be better if someone pointed out to me existing code rather than
chance my misunderstandings and errors.

					Andrew
					dalke@dalkescientific.com