[XML-SIG] Is this a bug?

Martijn Faassen faassen@vet.uu.nl
Sat, 27 Oct 2001 00:44:54 +0200


Martin v. Loewis wrote:
> > What does work is the following:
> > 
> > (Pdb) node.getAttributeNS(None, u'linkend')
> > u'Class:Scientific.BSP.ParValue'
> > 
> > Isn't that a bug? 
> 
> I have never verified this against the DOM spec, but the common theory
> is that this is not a bug in PyXML; if anything, it is a bug in the
> DOM.

The DOM lvl 2 spec has this to say:

"""
Note: DOM Level 1 methods are namespace ignorant. Therefore, while it is safe
to use these methods when not dealing with namespaces, using them and the new
ones at the same time should be avoided. DOM Level 1 methods solely identify
attribute nodes by their nodeName. On the contrary, the DOM Level 2 methods
related to namespaces, identify attribute nodes by their namespaceURI and
localName. Because of this fundamental difference, mixing both sets of methods
can lead to unpredictable results. In particular, using setAttributeNS, an
element may have two attributes (or more) that have the same nodeName,
but different namespaceURIs. Calling getAttribute with that nodeName could
then return any of those attributes. The result depends on the implementation.
Similarly, using setAttributeNode, one can set two attributes (or more) that
have different nodeNames but the same prefix and namespaceURI. In this case
getAttributeNodeNS will return either attribute, in an implementation dependent
manner. The only guarantee in such cases is that all methods that access a
named item by its nodeName will access the same item, and all methods which
access a node by its URI and local name will access the same node. For
instance, setAttribute and setAttributeNS affect the node that getAttribute
and getAttributeNS, respectively, return.
"""

I don't really understand the part that says "one can set two attributes (or
more) that have different nodeNames but the same prefix and namespaceURI. In
this case getAttributeNodeNS will return either attribute,"

It doesn't seem to make sense to me; a different nodeName like 'foo' means
getAttributeNodeNS asking for 'bar' in some namespace will never return
'foo', right?

Anyway, it does seem to indicate that getAttribute() should return *something*;
it's just not defined which one if there are multiple attributes with the
same nodeName but in different namespaces.

> In short, you are not supposed to mix namespace and non-namespace
> calls. If you build the tree through a parser that reports namespaces,
> you can only find the attributes through the namespace API.

This in itself isn't a bad policy to follow and perhaps making the
'getAttribute()' work according to the recommendation will only
confuse people more (if this behavior is spelled out in some
prominent place in the docs). It is however not what the recommendation
seems to say, though..

I'm only replying because I've been examining this spec too much the last
week, and I knew I just read something about this. :)
 
Regards,

Martijn