[XML-SIG] Major upcoming DOM changes in CVS

Greg Stein gstein@lyra.org
Wed, 17 Mar 1999 23:57:37 -0800

Andrew M. Kuchling wrote:
> Last night I embarked on a fairly extensive restructuring of the
> xml.dom.core module, to fix the outstanding problem with parent
> pointers; there are many cases where the existing code is unable to
> figure out the parent of a node.  This makes it difficult to walk from
> a node back to the root, which is unfortunately just what's required
> for implementing namespaces.

Actually, I use a stack to deal with namespace processing (in a
post-DOM-construction walk of the DOM tree). Each element can define any
number of prefixes, so my stack is a list (one item per element depth)
of dictionaries (prefix to URI mapping). When an element "starts", I
push an empty namespace map on, and when the elem "ends" I pop the

On each node, I record just the URI. The prefix is not relevant and must
actually be *removed*. It is very difficult to look for the
"multistatus" element in the "DAV:" namespace when the element name
could be "whatever-the-hell-namespace:multistatus".

Anyhow... once the DOM is constructed, the parent nodes are not

Oh... crap. Just thought of something. I'm viewing it from the "parse
XML into DOM" angle rather than the "build DOM to generate XML" angle. I
have no ideas for the latter... you actually would need some notion of
where a namespace is scoped and what prefix should be used. icky. (no
ideas... I don't think I would ever use a DOM to generate XML, so I've
never thought on it)

> BTW, once the DOM code has settled down again, I'd like to implement
> namespace handling for it, but I don't think anyone's proposed what
> that interface should look like.  Anyone have suggestions?

I just inserted a "namespace" attribute onto each _nodeData instance. It
did mean that I had to "know the insides" to insert and retrieve the
value, though.

I also ran into a *big* problem. _nodeData uses a mapping for the
attributes. The key is the attribute name. The key really should be a
namespace/name tuple.

For the "namespace" attribute, I use None to mean "no namespace" or a
string holding the namespace URI. During parsing, there are three types
of prefixes: None, empty string, non-empty string. None means no prefix
and no default namespace was defined; empty string means no prefix,
which refers to a defined, default namespace; non-empty means a prefix
which refers to a defined namespace.

Since my namespace processing was done during a post-construction walk,
the code might not be helpful. Let me know if you'd like it, tho, and
I'll post it.


p.s. I looked on the www-dom mailing list a couple days ago to see if
they had any suggestions for namespace APIs on the DOM... nada. not on
the list or in the draft. sigh.

Greg Stein, http://www.lyra.org/