Inconsistent treatment of attribute prefixes in DOM L3 Core and DOM L3 XPath

Hello.

     Appendix B of DOM L3 Core describes algorithms for namespace 
normalization [1] and namespace prefix lookup.[2]  The two algorithms 
differ in their treatment of prefixes on attributes.  The namespace 
normalization algorithm will ensure namespace declaration attributes exist 
for any element prefix or attribute prefix.  However, the namespace prefix 
lookup algorithm will only return an implicitly-declared prefix that is 
used in the name of an element, but not one that is used in the name of an 
attribute.

     To be more concrete, the following Java example

    Element e = doc.createElementNS("http://ex.org", "org:elem");
    Attr a = doc.createAttributeNS("http://ex.com", "com:att");
    a.setValue("abc");
    doc.appendChild(e);
    e.setAttributeNode(a);

    System.out.println("Before normalization:");
    System.out.println("Prefix associated with ex.org:  "
                + e.lookupPrefix("http://ex.org"));
    System.out.println("Prefix associated with ex.com:  "
                + e.lookupPrefix("http://ex.com"));

    System.out.println();

    doc.normalizeDocument();
    System.out.println("After normalization:");
    System.out.println("Prefix associated with ex.org:  "
                + e.lookupPrefix("http://ex.org"));
    System.out.println("Prefix associated with com:  "
                + e.lookupPrefix("http://ex.com"));

will produce the following output:

Before normalization:
Prefix associated with ex.org:  org
Prefix associated with ex.com:  null

After normalization:
Prefix associated with ex.org:  org
Prefix associated with ex.com:  com


     It's not clear why the prefix lookup algorithm ignores prefixes that 
are used on attribute nodes.  Was it an oversight?  The documentation of 
the algorithm doesn't explicitly point out this surprising fact, so it's 
not clear that this was a conscious decision.


     In a similar vein, according to section 1.2.3 of the W3C Note on DOM 
L3 XPath:[3]

<<
The set of in-scope namespaces of an element is the default xml namespace 
combined with the contributions of namespace attributes of the current and 
all ancestor elements.  In addition to explicit namespace attributes, any 
element has an implicit declaration of its own prefix, if any, or if no 
prefix then of the default namespace, which is enforced during namespace 
serialization, fixup, and lookup, which must be added to the set of 
in-scope namespaces when generating namespace nodes for an element. This 
causes the set of namespace nodes to be consistent with serialization, 
fixup, and lookup of namespaces in DOM Level 3. 
>>

     That text ensures that an element will have a namespace node that 
declares its own namespace.  However, there is no requirement that there 
be implicit declarations of namespaces for that element's attributes.

     The last sentence I've quoted from [3] indicates the set of 
namespaces will be consistent with fixup [1] and lookup of namespaces [2] 
in DOM Level 3.  It's not clear how the definition in [3] can be 
consistent with [1] and [2], when [1] and [2] are not consistent with one 
another.

Thanks,

Henry

[1] 
http://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#normalizeDocumentAlgo
[2] 
http://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#lookupNamespacePrefixAlgo
[3] 
http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226/xpath.html#NamespaceNodes

------------------------------------------------------------------
Henry Zongaro      Xalan development
IBM SWS Toronto Lab   T/L 969-6044;  Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com

Received on Tuesday, 16 November 2004 15:22:46 UTC