summaryrefslogtreecommitdiffstats
path: root/Lib/xml/dom/minidom.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/minidom.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/minidom.py')
-rw-r--r--Lib/xml/dom/minidom.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py
index b026fbb..ef1a2bf 100644
--- a/Lib/xml/dom/minidom.py
+++ b/Lib/xml/dom/minidom.py
@@ -651,17 +651,23 @@ class DOMImplementation:
doc = Document()
if doctype is None:
doctype = self.createDocumentType(qualifiedName, None, None)
- if qualifiedName:
- prefix, localname = _nssplit(qualifiedName)
- if prefix == "xml" \
- and namespaceURI != "http://www.w3.org/XML/1998/namespace":
- raise xml.dom.NamespaceErr("illegal use of 'xml' prefix")
- if prefix and not namespaceURI:
- raise xml.dom.NamespaceErr(
- "illegal use of prefix without namespaces")
- element = doc.createElementNS(namespaceURI, qualifiedName)
- doc.appendChild(element)
- # XXX else, raise an error? Empty qname is illegal in the DOM spec!
+ if not qualifiedName:
+ # The spec is unclear what to raise here; SyntaxErr
+ # would be the other obvious candidate. Since Xerces raises
+ # InvalidCharacterErr, and since SyntaxErr is not listed
+ # for createDocument, that seems to be the better choice.
+ # XXX: need to check for illegal characters here and in
+ # createElement.
+ raise xml.dom.InvalidCharacterErr("Element with no name")
+ prefix, localname = _nssplit(qualifiedName)
+ if prefix == "xml" \
+ and namespaceURI != "http://www.w3.org/XML/1998/namespace":
+ raise xml.dom.NamespaceErr("illegal use of 'xml' prefix")
+ if prefix and not namespaceURI:
+ raise xml.dom.NamespaceErr(
+ "illegal use of prefix without namespaces")
+ element = doc.createElementNS(namespaceURI, qualifiedName)
+ doc.appendChild(element)
doctype.parentNode = doc
doc.doctype = doctype
doc.implementation = self
@@ -761,6 +767,7 @@ def _doparse(func, args, kwargs):
events = apply(func, args, kwargs)
toktype, rootNode = events.getEvent()
events.expandNode(rootNode)
+ events.clear()
return rootNode
def parse(*args, **kwargs):