[XML-SIG] New to Python OO
uche.ogbuji@fourthought.com
uche.ogbuji@fourthought.com
Fri, 11 Dec 1998 17:59:06 -0700
> 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").
This is an excellent point. We are currently working on introducing the
visitor pattern into 4DOM for the next version or two, over which we would
overlay a global function, tentatively VisitInOrder(), which does the
equivalent of the walker on PyDOM by doing an in-order traversal and invoking
accept(AppropriateVisitor) on each of the DOM nodes. We like this idea
because of the extensibility: we can then have visitors that print out raw
text, or that pretty-print with extra whitespace. A user could add his own
visitor that performs transforms as you mention, etc.
> 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?
It seems to me that your example above is definitely not in the domain of
style-sheets, but DOM programming. I guess I could imagine the ECMAScript to
do it in XSL, but it just makes me ask "why?".
A DOM visitor, or a SAX application, however, appear far more appropriate ways
to do this.
--
Uche Ogbuji
FourThought LLC, IT Consultants
uche.ogbuji@fourthought.com (970)481-0805
Software engineering, project management, Intranets and Extranets
http://FourThought.com http://OpenTechnology.org