By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,218 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,218 IT Pros & Developers. It's quick & easy.

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

P: n/a
[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.
from xml.dom.minidom import Text
t = Text("foo")
t <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. from xml.dom.minidom import Text
t = Text("foo") 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:
t = Text()
t

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?
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hans Nowak wrote:
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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.