[XML-SIG] Fate of pydom.py?

A.M. Kuchling akuchlin@cnri.reston.va.us
Wed, 7 Oct 1998 21:13:38 -0400

pydom.py is a little module that forms part of the DOM package; the
docstring describes it as "DOM element construction using Python
syntax.".  It defines a subclass of the Element class which adds a bit
of syntactic sugar to element creation.  It accepts a variable number
of regular and keyword arguments.  Dictionaries are treated as
containing name,attribute pairs, as are keyword arguments.  Tuples and
lists are assumed to contain other nodes which will become children of
the new Element node; strings are converted to Text nodes and added as

An example will help.  To create this pseudo-HTML XML:

<body background="#ffffff" textcolor="#000000">
I'm the first paragraph.

You could do this:

h1 = Element('H1', 'Heading')
body = Element(h1, "I'm the first paragraph", 
               {'background':'#ffffff'}, textcolor = "#000000")

There's also the start of some operator overloading; the Element class
has an __lshift__ function which inserts the right-hand argument at
the front of the children, so parent << child will add the child to
the parent node.

Question: What should we do with pydom.py?  My inclination is to drop
it.  I don't mind adding some syntactic sugar to Element creation,
though I'd like to simplify it; perhaps just having keywords added as
attributes, so Element('body', background='#ffffff', textcolor =
'#000000') would work.

I'm less sure about the operator overloading idea, and would prefer to
drop it.  There doesn't seem to be a natural mapping between tree
operations and Python's operators.  Using << and >> for appending at
either end seems like a bit of a stretch, for example.  Also, it might
sometimes be confusing; if + is used for append, for example, people
might expect TextNode + "foo" to change the string value of TextNode.  

If no one voices any opinions on this, I'll drop pydom.py, and add the
keyword shortcut to Document.createElement().

A.M. Kuchling			http://starship.skyport.net/crew/amk/
I've always believed that guilt was an emotion for weaker men -- so where does
that leave me?
    -- Wesley Dodds, in SANDMAN MYSTERY THEATRE: "The Cannon", act I