DOM implementation

Emanuele D'Arrigo manu3d at
Fri May 15 12:27:17 EDT 2009

Hi Paul, thank you for your swift reply!

On May 15, 3:42 pm, Paul Boddie <p... at> wrote:
> Sure! Just keep your observations coming! I've made a very lazy
> attempt at DOM Events support in libxml2dom,

I just had a look at libxml2dom, in particular its file.
Given that we are working from a standard your implementation is
exceedingly similar to mine and had I know before I started writing my
own classes I would have started from it instead! =)
Browsing through the code, the EventTarget class docstring reads:

    The listeners for a node are accessed through the global object.
This common
    collection is consequently accessed by all nodes in a document,
meaning that
    distinct objects representing the same node can still obtain the
set of
    listeners registered for that node. In contrast, any attempt to
    store listeners on particular objects would result in the specific
    which registered the listeners holding the record of such objects,
    other objects obtained independently for the same node would hold
no such

Naively, I implemented my EventTarget class storing its own listeners
rather than global ones. Nevertheless, I'm not quite understanding
this issue. Why shouldn't the listeners be stored directly on the
EventTarget? I have a glimpse of understanding that if the
DOMImplementation keeps EventTarget and Nodes (or Elements? which
entity is supposed to support Events?) separate this might be
necessary. But beside the fact that it's just a fuzzy and potentially
incorrect intuition, I seem to think that the appropriate way to
proceed would be for the DOMImplementation to provide a Node class
that also inherits from EventTarget. In so doing the listeners would
be immediately accessible as soon as one has a handle to a Node.

Furthermore, your code finds the bubbling route with the line:

bubble_route = target.xpath("ancestor::*")

That xpath method is a libxml method right?

> (...) although I find these things quite hard to
> figure out with the usual vagueness of the specifications on certain
> crucial implementation-related details (and that there's a mountain of
> specifications that one has to navigate).

Indeed there is some vagueness in the W3C recommendations and the
various documents offer very little redundancy with each other but
require you to be knowledgeable about them all! I'm managing to piece
together the pieces of the puzzle only after a couple of day having an
in-depth read-through of DOM, DOM Events and a little bit of XML
events to see how it all works in practice. XML events is also what's
prompting me to think that Node/Elements classes of the implementation
should also inherit from EventTarget as they can all be event

> One of my tests tries to exercise the code, but I might be doing it
> all completely wrong:

Before I can comment I'd like to better understand what you are aiming
for with libxml2dom. It seems to be providing some kind of conversion
services from the xml structure generated by libxml to a dom-like
structure (implemented by pxdom?).
Is that correct?

> It occurs to me that various PyQt- and PyKDE-related bindings might
> also provide some exposure to DOM Events, although I had heard that
> WebKit, which should have support for lots of DOM features, exposes
> some pretty useless interfaces to languages like Python, currently.
> The situation with Mozilla and PyXPCOM may well be similar.

PyKDE is off-limits because it's unix only while I'm trying to be
cross-platform. PyQT is interesting. Very. Further investigation is
required. =)


More information about the Python-list mailing list