[XML-SIG] minidom/pulldom connection

Mike Olson Mike.Olson@fourthought.com
Thu, 23 Nov 2000 03:28:09 -0700


Greg Stein wrote:
> 
> Before: each time you called startDocument(), it would start a new document.
> Now, it will only do so the first time.
> 
> I would recommend passing a class (a constructor, really) object to __init__
> and storing that constructor. startDocument() can then call it
> unconditionally like before.
>
>     def __init__(self, cls=xml.dom.minidom.Document):
>     ...


Why not take it one step further, and pass an instance of a
DOMImplementation into the contructor.  The reason I don't like to class
idea, is you limit DOM implementors, now all document contructors must
default all parameters (or not have any).  As an example, I'm working on
a persistent DOM implementation that will probably need a database
connection in it contructor.

I don't rememeber if minidom has a DOMImplementation though, however its
trivial to write.

Mike

> 
> [ this does imply moving the import back to the global scope ]
> 
> Cheers,
> -g

> 
> On Wed, Nov 22, 2000 at 03:40:07PM -0500, Fred L. Drake, Jr. wrote:
> Content-Description: message body and .signature
> >
> > Fred L. Drake, Jr. writes:
> >  >   I'm proposing the attached patch to pulldom.
> >
> >   Which I'm actually attaching this time...
> >
> >
> >   -Fred
> >
> > --
> > Fred L. Drake, Jr.  <fdrake at acm.org>
> > PythonLabs at Digital Creations
> >
> 
> Content-Description: patch to xml.dom.pulldom
> > Index: pulldom.py
> > ===================================================================
> > RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/pulldom.py,v
> > retrieving revision 1.11
> > diff -c -r1.11 pulldom.py
> > *** pulldom.py        2000/10/23 18:09:50     1.11
> > --- pulldom.py        2000/11/22 20:38:20
> > ***************
> > *** 1,4 ****
> > - import minidom
> >   import xml.sax,xml.sax.handler
> >
> >   START_ELEMENT = "START_ELEMENT"
> > --- 1,3 ----
> > ***************
> > *** 11,17 ****
> >   CHARACTERS = "CHARACTERS"
> >
> >   class PullDOM(xml.sax.ContentHandler):
> > !     def __init__(self):
> >           self.firstEvent = [None, None]
> >           self.lastEvent = self.firstEvent
> >           self._ns_contexts = [{}] # contains uri -> prefix dicts
> > --- 10,17 ----
> >   CHARACTERS = "CHARACTERS"
> >
> >   class PullDOM(xml.sax.ContentHandler):
> > !     def __init__(self, document=None):
> > !         self.document = document
> >           self.firstEvent = [None, None]
> >           self.lastEvent = self.firstEvent
> >           self._ns_contexts = [{}] # contains uri -> prefix dicts
> > ***************
> > *** 121,127 ****
> >           self.lastEvent = self.lastEvent[1]
> >
> >       def startDocument(self):
> > !         node = self.curNode = self.document = minidom.Document()
> >           node.parentNode = None
> >           self.lastEvent[1] = [(START_DOCUMENT, node), None]
> >           self.lastEvent = self.lastEvent[1]
> > --- 121,130 ----
> >           self.lastEvent = self.lastEvent[1]
> >
> >       def startDocument(self):
> > !         if self.document is None:
> > !             import xml.dom.minidom
> > !             self.document = xml.dom.minidom.Document()
> > !         node = self.curNode = self.document
> >           node.parentNode = None
> >           self.lastEvent[1] = [(START_DOCUMENT, node), None]
> >           self.lastEvent = self.lastEvent[1]
> 
> --
> Greg Stein, http://www.lyra.org/
> 
> _______________________________________________
> XML-SIG maillist  -  XML-SIG@python.org
> http://www.python.org/mailman/listinfo/xml-sig

-- 
Mike Olson				 Principal Consultant
mike.olson@fourthought.com               (303)583-9900 x 102
Fourthought, Inc.                         http://Fourthought.com 
Software-engineering, knowledge-management, XML, CORBA, Linux, Python