[XML-SIG] New to Python OO

Gabe Wachob gwachob@aimnet.com
Fri, 11 Dec 1998 13:19:35 -0800 (PST)


On Fri, 11 Dec 1998, Andrew M. Kuchling wrote:

> >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.)

(Speaking of the Python DOM implementation here)

The Walker class is sort of a Visitor (not really). The walker "calls
back" (really calls methods of its subclass) methods when the walker first
visits and when the walker leaves a particular Node (assuming a depth
first left-to-right traversal). 

A Visitor pattern class would not neccesarily include the "traversal"
function (subclasses could) -- it would simply have "handleElement", 
"handleAttribute", "handleText", etc (sorta like SAX). A visitor pattern
would handle an entire "subtree" at a time (I would guess) instead of
thinking of the tree in a traversal sense (ie "startElement",
"endElement"). 

It seems to me conceptually cleaner for most applications (if somewhat
less efficient in some cases) to deal with the tree structurally instead
of procedurally and thats why I would like to see a Visitor pattern..

Ultimately, it would be nice to be able to encode "transform" functions on
trees -- approaching and surpassing the functionality of XSL from a
programmtic (instead of stylesheet) point of view. For example (in prose):

Take all the children of the "AUTHOR" element which have the attribute
"INFORMATION" value of "PRIVATE" and compute a funciton on that attribute
value and put it in a list. 

XSL can do a lot of this, but not all (or at least not cleanly, IMHO). 

Thoughts?

	-Gabe

-------------------------------------------------------------------
http://www.aimnet.com/~gwachob               http://www.findlaw.com
"A popular Government, without popular information, or the means of 
acquiring it, is but a Prologue to a Farce or a Tragedy; or perhaps 
both." -- James Madison 
                       import std.disclaimer