[XML-SIG] Is this a bug?

Martijn Faassen faassen@vet.uu.nl
Mon, 29 Oct 2001 14:36:23 +0100


Martin v. Loewis wrote:
> > 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?
> 
> This probably deals with the case
> 
> <root xmlns:foo="http://www.python.org/ns">
>   <node xmlns:bar="http://www.python.org/ns">
>     <elem foo:attr="1"/>
>   </node>
> </root>
> 
> Given elem, you can now do
> 
>   a1 = elem.documentNode.createAttribute("bar:attr")
>   a1.nodeValue = "2"
>   elem.setAttributeNode(a1)
> 
> Now, you do
> 
>   elem.getAttributeNS("http://www.python.org/ns", "attr")
> 
> This could return either "1" or "2", depending on the implementation.

Hm, yeah, I didn't realize nodeName would include the prefix here, but
I see in the DOM spec that Element.tagName is the qualifiedName, which
can include prefix.

Note by the way that doing:

elem.ownerDocument.createAttribute("bar:attr") is unlikely to actually
put attr into any namespace. I've been hunting the DOM recommendation
for clarification recently, and it's vague, but I think the DOM
actually does not need to have any knowledge of namespace scoping
rules; it doesn't need to know 'bar' is the prefix for the
"http://www.python.org/ns" namespace URI in that spot. Namespaces in the
DOM are always created explicitly, never seem to be deduced from
scope in the document. At least this is my interpretation, I've asked
a question on www-dom for some clarification on this issue.

Some evidence:

namespaceURI of type DOMString, readonly, introduced in DOM Level 2

 The namespace URI of this node, or null if it is unspecified.
 This is not a computed value that is the result of a namespace lookup based
 on an examination of the namespace declarations in scope. It is merely the
 namespace URI given at creation time.

I actually appreciate the explictness of namespaces in the DOM, even
though there's a mismatch with usage in XML. It simplifies implementation
a lot, which is badly needed as so many parts of the spec *complicate*
implementation (liveness issues are just one example).

> > 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.
> 
> I agree. So to me, it seems that there is a number of bugs in 4DOM in
> that respsect.

Zope's ParsedXML has a large DOM unit test suite which can be run against
4DOM as well. I've recently been advocating getting this test suite out
of ParsedXML and into PyXML instead. This way we can make sure the Python
DOM implementations are up to spec much better.

Of course the test suite can contain wrong interpretations of the DOM
spec as well, but a lot of care was taken during the development of it,
and it can be further improved should problems appear.

Regards,

Martijn