RE: Why does the default namespace not apply to attributes?

Noah, thank you for your answer. > <!-- prefix p and the default are bound to the same namespace URI > -_>> <outer xmlns="http://example.org/ns" > xmlns:p="http://example.org/ns">> <-- no duplicate attribute error in the following -->> <inner a="1" p:a="2"/>> <-- the following has the same element tag as the one above -->> <p:inner />> </outer>I see that your example presents a valid piece of XML, but I believe there are other – more readable - ways to have two attributes with the same name in one element. I believe the XML in your example leads to confusion, as to which namespace the attributes belong, especially because elements don’t need a prefix to indicate they belong to the target namespace, whereas attributes do. At first sight, one would think that both “a” and “p:a” belong to the same namespace (the same that is also associated with the “inner” and “outer” element), whereas actually the first occurrence of “a” does not belong to a namespace at all. Wouldn’t it be more intuitive and improve readability to have both of the attributes in a different namespace, instead of one attribute being in no namespace? Let’s say, if the default namespace would apply to attributes, the following two examples would represent the same thing, i.e. the “p:a” would be equal to the “a”.Example 1---------<!-- prefix p and the default are bound to the same namespace URI --><outer xmlns="http://example.org/ns"        xmlns:p=http://example.org/ns       xmlns:q=http://example2.org/ns>  <-- no duplicate attribute error in the following -->  <inner p:a="1" q:a="2">  <-- the following has the same element tag as the one above -->  <p:inner /></outer>Example 2---------<!-- prefix p and the default are bound to the same namespace URI --><outer xmlns="http://example.org/ns"        xmlns:p=http://example.org/ns       xmlns:q=http://example2.org/ns>  <-- no duplicate attribute error in the following -->  <inner a="1" q:a="2">  </inner></outer>Nevertheless, per [1] attribute “a” in Example 2 does not belong to same namespace as “p:a” in Example 1, thus the examples do not represent the same thing. > Reading between the lines, the Namespaces recommendation takes the view > that attributes tend to be scoped to the elements on which they appear. I saw this statement as well, but to me it does not provide sufficient rationale for not applying the default namespace to attributes.> Also, it's quite common in colloquial XML usage, to find unqualified > attributes on qualified elements.Probably, this is because normally one doesn’t really notice the difference and as long as a document validates, many people don’t think about it. It only becomes clear when you start referencing them (e.g using “key” and “keyref”) and see that the document does not validate if you use a prefix both for the element and the attribute (because the attribute does not belong to the same namespace).XML Schema snippet------------------<xs:element name=”inner” type=”innerType”>  ....  <xs:attribute name=”a” type=”aType”/></xs:element>XML instance snippet (INVALID)------------------------------<xsd:keyref refer="key" name="keyRef">  <xsd:selector xpath=".//p:inner"/>  <xsd:field xpath="@p:a"/></xsd:keyref>In summary I would say that your answer has not yet convinced me and I look forward to continuation of the discussion. Best regards,Nanda[1] http://www.w3.org/TR/REC-xml-names/#uniqAttrs> To: nandakol@hotmail.com> CC: xmlschema-dev@w3.org> Subject: Re: Why does the default namespace not apply to attributes?> From: noah_mendelsohn@us.ibm.com> Date: Thu, 16 Aug 2007 14:26:58 -0400> > Speaking for myself, and not formally for the Schemas WG:> > the decision in Schemas to treat elements and attributes asymmetrically > reflects a related asymmetry in namespaces itself.  You'll note that per > XML Namespaces [1], default namespace bindings to not apply to attributes. >  You can see this because per the namespaces recommendation, the following > example does NOT have a duplicate attibute (it's actually not important > that I've used two elements here, it's just easier to separate the > namespace bindings from the attributes:> > >         <!-- prefix p and the default are bound to the same namespace URI > -_>>         <outer xmlns="http://example.org/ns" > xmlns:p="http://example.org/ns">>           <-- no duplicate attribute error in the following -->>           <inner a="1" p:a="2"/>>           <-- the following has the same element tag as the one above -->>           <p:inner />>         </outer>> > Reading between the lines, the Namespaces recommendation takes the view > that attributes tend to be scoped to the elements on which they appear. > Also, it's quite common in colloquial XML usage, to find unqualified > attributes on qualified elements.  Finally, while the connection is > indirect, DTDs do treat attributes as local to the element;  you can tell > this because you can declare different default values for attribute "A" on > element "E1" vs. element "A" on "E2".  For all of these reasons, Schemas > defaults to a model in which attributes are unqualified, even if a > targetNamespace is declared for a schema document.> > Noah> > [1] http://www.w3.org/TR/REC-xml-names/#uniqAttrs> > --------------------------------------> Noah Mendelsohn > IBM Corporation> One Rogers Street> Cambridge, MA 02142> 1-617-693-4036> --------------------------------------> > > > > > > > > Nanda Kol <nandakol@hotmail.com>> Sent by: xmlschema-dev-request@w3.org> 08/16/2007 11:32 AM>  >         To:     <xmlschema-dev@w3.org>>         cc:     (bcc: Noah Mendelsohn/Cambridge/IBM)>         Subject:        Why does the default namespace not apply to > attributes?> > > All,>  > The following question is about the rationale for the difference in > approach between elements and attributes with regard to namespaces.>  > In order to promote reuse of XML artifacts within our organization, a set > of recommendations has been specified for XML Schema documents design. One > of the recommendations is that every XML Schema document should have a > target namespace. However, after some experiments and investigation we > learnt that this namespace does not apply to attributes, which means that > the use of a target namespace results in attributes and elements being in > different conceptual spaces, which seems counter-intuitive. >  > We have been wondering what could be the rationale behind this, but > couldn’t find the answer. Hopefully, you can provide it or you know where > to search for it.>  > Moreover, if you can provide us any directions on the best approach  (i.e. > set attributeFormDefault to “qualified”, use global attribute > declarations, or else) with respect to reusability, this would be more > than welcome.>  > Thanks in advance,> Nanda> > Play free games, earn tickets, get cool prizes! Join Live Search Club.   > Join Live Search Club!> 
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

Received on Monday, 20 August 2007 08:10:01 UTC