summaryrefslogtreecommitdiffstats
path: root/Lib/xml/dom/pulldom.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-02-06 01:16:06 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-02-06 01:16:06 (GMT)
commitb417be2ad9c4d4d7ab9d682f71c771de37a48dcc (patch)
tree5d0261a33c1beffb4d56908de64c5c1fb6643628 /Lib/xml/dom/pulldom.py
parent269b83bc05452f4f54fa9df5a76608f88da544fe (diff)
downloadcpython-b417be2ad9c4d4d7ab9d682f71c771de37a48dcc.zip
cpython-b417be2ad9c4d4d7ab9d682f71c771de37a48dcc.tar.gz
cpython-b417be2ad9c4d4d7ab9d682f71c771de37a48dcc.tar.bz2
Do not allow empty qualifiedName in createDocument.
Rearrange pulldom to create documents with root element. Provide clear methods so that the ContentHandler releases its hold on the document.
Diffstat (limited to 'Lib/xml/dom/pulldom.py')
-rw-r--r--Lib/xml/dom/pulldom.py37
1 files changed, 29 insertions, 8 deletions
diff --git a/Lib/xml/dom/pulldom.py b/Lib/xml/dom/pulldom.py
index c400742..b573ba0 100644
--- a/Lib/xml/dom/pulldom.py
+++ b/Lib/xml/dom/pulldom.py
@@ -61,11 +61,17 @@ class PullDOM(xml.sax.ContentHandler):
tagName = prefix + ":" + localname
else:
tagName = localname
- node = self.document.createElementNS(uri, tagName)
+ if self.document:
+ node = self.document.createElementNS(uri, tagName)
+ else:
+ node = self.buildDocument(uri, tagName)
else:
# When the tagname is not prefixed, it just appears as
# localname
- node = self.document.createElement(localname)
+ if self.document:
+ node = self.document.createElement(localname)
+ else:
+ node = self.buildDocument(None, localname)
for aname,value in attrs.items():
a_uri, a_localname = aname
@@ -90,7 +96,10 @@ class PullDOM(xml.sax.ContentHandler):
self.lastEvent = self.lastEvent[1]
def startElement(self, name, attrs):
- node = self.document.createElement(name)
+ if self.document:
+ node = self.document.createElement(name)
+ else:
+ node = self.buildDocument(None, name)
for aname,value in attrs.items():
attr = self.document.createAttribute(aname)
@@ -127,23 +136,28 @@ class PullDOM(xml.sax.ContentHandler):
self.lastEvent = self.lastEvent[1]
def startDocument(self):
- publicId = systemId = None
- if self._locator:
- publicId = self._locator.getPublicId()
- systemId = self._locator.getSystemId()
if self.documentFactory is None:
import xml.dom.minidom
self.documentFactory = xml.dom.minidom.Document.implementation
- node = self.documentFactory.createDocument(None, publicId, systemId)
+
+ def buildDocument(self, uri, tagname):
+ # Can't do that in startDocument, since we need the tagname
+ # XXX: obtain DocumentType
+ node = self.documentFactory.createDocument(uri, tagname, None)
self.document = node
self.lastEvent[1] = [(START_DOCUMENT, node), None]
self.lastEvent = self.lastEvent[1]
self.push(node)
+ return node.firstChild
def endDocument(self):
self.lastEvent[1] = [(END_DOCUMENT, self.document), None]
self.pop()
+ def clear(self):
+ "clear(): Explicitly release parsing structures"
+ self.document = None
+
class ErrorHandler:
def warning(self, exception):
print exception
@@ -199,6 +213,13 @@ class DOMEventStream:
self.pulldom.firstEvent[1] = self.pulldom.firstEvent[1][1]
return rc
+ def clear(self):
+ "clear(): Explicitly release parsing objects"
+ self.pulldom.clear()
+ del self.pulldom
+ self.parser = None
+ self.stream = None
+
class SAX2DOM(PullDOM):
def startElementNS(self, name, tagName , attrs):