Re: pyexpat: Comments before DOCTYPE

Ingo van Lil <[email protected]>
Newsgroups gmane.comp.python.xml
Message-ID <[email protected]>
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

_______________________________________________
XML-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/xml-sig
python-2.4.2-expatbuilder.patch (text/plain, 582 B)
--- 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.