[XML-SIG] New to Python OO

Andrew M. Kuchling akuchlin@cnri.reston.va.us
Fri, 11 Dec 1998 15:30:17 -0500 (EST)


Michael Sanborn writes:
>imports xml.dom.core and xml.dom.builder. I would have thought that the
>way to approach this would be to define a local Node class derived from
>core.py that added an empty totxt() method, and then to define local
>subclasses of Node (such as Text) with specific totxt() methods. 

	Things aren't that simple, because of the implementation,
which consists of a tree of hidden objects; the classes that you
interact with, such as Node, Element, Text, etc. are all proxies for
that hidden tree, and create new Node, Element, Text, ... proxies when 
you request a new portion.  So all the retrieval methods would have to 
be aware 
	
>My
>reasoning was that the Builder class would then build the tree with my
>enhanced Nodes. But that doesn't seem to be happening. Instead, Builder
>seems to be constructing the tree with regular core Nodes that don't
>recognize my totxt() method. Can anyone give me advice on how to achieve
>this?

	My suspicion is that subclassing Node classes isn't the way to
go; instead, you'll write functions and classes (probably using
existing classes such as Builder and Walker) that operate on DOM
trees.  However I'd really like to see a discussion of this.  We need
to work out common Python/DOM patterns, so that we can add appropriate
helper modules and functions.  (They'll also be useful to document as
examples.)

-- 
A.M. Kuchling			http://starship.skyport.net/crew/amk/
The multiple human needs and desires that demand privacy among two or more
people in the midst of social life must inevitably lead to cryptology wherever
men thrive and wherever they write.
    -- David Kahn, _The Codebreakers_