[XML-SIG] pyexpat: Comments before DOCTYPE

Ingo van Lil inguin at gmx.de
Mon Feb 13 21:47:25 CET 2006


On 13 Feb 2006, Ingo van Lil wrote:

> I ran into a minor problem using the xml.dom.minidom XML parser: An XML
> document having a comment before a DOCTYPE node seems to leave the DOM
> data structures in an inconsistent state.

Hi again. I had a look at the source code, and the reason for the effect
I observed isn't all that hard to spot: The start_doctype_decl_handler
in expatbuilder.py:240 directly manipulates the document's childNodes
vector rather than using the _append_child function responsible for
keeping all those nextSibling/previousSibling/parentNode pointers
up-to-date.
Unless the current behaviour is for some reason intentional (I doubt
it), the appended patch (against Python 2.4.2) should fix the problem.

        Cheers,
            Ingo

-------------- next part --------------
--- Lib/xml/dom/expatbuilder.py.orig	2006-02-13 20:53:44.000000000 +0100
+++ Lib/xml/dom/expatbuilder.py	2006-02-13 20:55:29.000000000 +0100
@@ -242,7 +242,7 @@
         doctype = self.document.implementation.createDocumentType(
             doctypeName, publicId, systemId)
         doctype.ownerDocument = self.document
-        self.document.childNodes.append(doctype)
+        _append_child(self.document, doctype)
         self.document.doctype = doctype
         if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT:
             self.document.doctype = None


More information about the XML-SIG mailing list