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

Discussion in 'Python' started by Hans Nowak, Sep 4, 2003.

  1. Hans Nowak

    Hans Nowak Guest

    [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?
    Hans Nowak, Sep 4, 2003
    #1
    1. Advertising

  2. 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
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Sep 4, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hans Nowak
    Replies:
    0
    Views:
    324
    Hans Nowak
    Sep 4, 2003
  2. Greg Wogan-Browne
    Replies:
    1
    Views:
    804
    Uche Ogbuji
    Jan 28, 2005
  3. Replies:
    3
    Views:
    533
    Stefan Behnel
    Aug 3, 2007
  4. Replies:
    6
    Views:
    1,963
  5. Johannes Bauer
    Replies:
    7
    Views:
    1,065
    Johannes Bauer
    Jun 11, 2009
Loading...

Share This Page