[Doc-SIG] How to traverse a document object

Paul Moore gustav@morpheus.demon.co.uk
Wed, 24 Oct 2001 22:31:11 +0100

On Wed, 24 Oct 2001 09:40:19 +0100, "Tony J Ibbs (Tibs)"
<tony@lsl.co.uk> wrote:

>David Goodger wrote:
>> If you insert methods from outside the module, yes, you *would* be
>> presumptuous.
>Ah, but the advantage we have with the DPS nodes tree is that one *can*
>be presumptuous - it doesn't get one very far with "classic" DOM!

Hmm. Why not - it's a feature of the language (Python) that you can
insert methods into predefined classes. That applies to DPS node classes
or XML DOM classes equally. You need to know some details of the
implememtation, but that's where the presumption comes in...

(And whether it's a *good* thing is a separate point).

>For clarification, my (quick and dirty) HTML output mode works with a
>dictionary that links tag name to method name [1]_, with a special case
>for "#text" ('cos it's special). Thus it doesn't actually assume much
>about what includes what (although things will go strange if the
>structure is *not* what one would expect from the spec).

Yes, I looked at your stuff and saw that. It's nice and general. There's
some "feel" to it that still feels adhoc to me. Can't put my finger on
it, though. It's one of those cases where I suspect there's a "clearly
right" solution, and all of the other options lack that "spark" of
clarity and "obvious rightness". Om...

>Since I rather want a Writer class that can be customised easily, this
>dictionary approach seems simplest for the initial development - it's
>easy to subclass the Writer and just amend the dictionary entries.

I hadn't thought of subclassing and changing the dictionary. Yes, that
makes it nicely reusable.

>I'm sure some visitor model would be nice at some stage, though - once
>one has understood the thing (!) it works very nicely (cf. the
>``compiler`` package).

The visitor pattern is nice. However, it relies on co-operation from the
class being visited, and getting the form of that co-operation right is
hard (you're designing a general tree-walk framework, often without
knowing all the ways it might need to be used - after all, you can't
modify it in response to client requirements, that's the point.)