Strange problem with xml.dom.minidom Text object (Python 2.3)

H

Hans Nowak

[Not sure if this message made it, so I'm resending it... apologies if it
appears multiple times.]


Howdy y'all,

The following works in Python 2.2.2:

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.<DOM Text node "foo">

So far, so good. We have production code that uses the Text class by
initializing it with a string, and it works well. However:

(C:\work\uq\ticket_parse) $ \Python23\python.exe
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: this constructor takes no arguments

So I thought, maybe this was disallowed for some reason. What happens if we
create the object without arguments? It works, but when doing a __repr__, the
object lacks the .data attribute, which is odd:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python23\lib\xml\dom\minidom.py", line 956, in __repr__
data = self.data
AttributeError: Text instance has no attribute 'data'

Anybody knows what's going on here? I didn't see this as a bug in the
BugTracker. Am I doing something wrong?
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Hans said:
Anybody knows what's going on here? I didn't see this as a bug in the
BugTracker. Am I doing something wrong?

Yes. Your are not supposed to create Text objects (or any other DOM
nodes) by calling the implementation class. Instead, you should use the
DOM interfaces to obtain new nodes. In the specific case, call
..createTextNode on the Document object. See the documentation for details.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top