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

noreply@sourceforge.net noreply@sourceforge.net
Thu, 04 Jan 2001 07:54:45 -0800


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

Project: Python
Category: XML
Status: Open
Resolution: None
Bug Group: None
Priority: 6
Submitted by: akuchling
Assigned to : akuchling
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.



Follow-Ups:

Date: 2001-Jan-04 07:54
By: fdrake

Comment:
Andrew, didn't you mostly fix this?  If you're done, please close the bug
report.

(One thing to check:  it doesn't look like NamedNodeMap.setNamedItem() and
.setNamedItemNS() check that the inserted node is an ATTRIBUTE_NODE; if
not, HierarchyRequestErr should be raised.)

Thanks for working on this!
-------------------------------------------------------

Date: 2000-Dec-12 13:08
By: gvanrossum

Comment:
Reassigning to Fred so he can pressure Paul into doing something about this.
-------------------------------------------------------

Date: 2000-Nov-23 08:07
By: akuchling

Comment:
Patch #102485 has been submitted to fix this.
-------------------------------------------------------

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

Comment:
Oops, should re-categorize this as "XML" while I'm at it.
-------------------------------------------------------

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

Comment:
>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).
-------------------------------------------------------

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

Comment:
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-Oct-12 20:02
By: fdrake

Comment:
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.
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=116678&group_id=5470