[Python-bugs-list] [Bug #116678] minidom doesn't raise exception for illegal children

noreply@sourceforge.net noreply@sourceforge.net
Tue, 21 Nov 2000 14:33:06 -0800

Bug #116678, was updated on 2000-Oct-11 19:30
Here is a current snapshot of the bug.

Project: Python
Category: Library
Status: Open
Resolution: None
Bug Group: None
Priority: 6
Summary: minidom doesn't raise exception for illegal children

Details: Some types of DOM node such as Text can't have children.
minidom doesn't check for this at all:

from xml.dom import minidom
doc = minidom.Document()
text = doc.createTextNode('lorem ipsum')
elem = doc.createElement('leaf')
text.appendChild( elem )
print text.toxml()

This outputs just 'lorem ipsum', but elem really is a child 
of text; Text.toxml() just isn't recursing because it doesn't expect to do so.


Date: 2000-Oct-12 20:02
By: fdrake

This is a bug with detecting an improper use.  It should be fixed, but need not be for Python 2.0.  Correct use will not produce erroneous behavior.  Reducing priority by one.

Date: 2000-Oct-15 07:06
By: loewis

I believe this is not a bug, but an intended deviation from the DOM spec.
minidom (as the proposed documentation in patch 101821 explains) does
not support the IDL exceptions of module DOM, so it cannot report errors about improper usage.

Date: 2000-Nov-21 14:33
By: fdrake

From the documentation, I'd expect the Pythonic "moral equivalents" to be raised, which would be a ValueError in the case of illegal node types.

I'll even go so far as to say that ValueError should be raised when a second documentElement is appended, instead of a TypeError, to be more consistent with usage else where in the standard library:  Pythonic style is to raise a ValueError when the type of a value is right (in this case, a DOM Node), but the specific value is not acceptable, either because it is illegal or because it cannot be accepted given existing state (like already having a documentElement).

For detailed info, follow this link: