Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Namespaces & prefixed attributes (one more time) (http://www.velocityreviews.com/forums/t166955-namespaces-and-prefixed-attributes-one-more-time.html)

kj 04-21-2004 12:25 PM

Namespaces & prefixed attributes (one more time)
 


In an earlier thread, JKrugman posted the following quote:

> ...the purpose of XML namespaces is to uniquely identify element
> and attribute names. Unprefixed attribute names can be uniquely
> identified based on the element type to which they belong, so
> there is no need identify them further by including them in an
> XML namespace. In fact, the only reason for allowing attribute
> names to be prefixed is so that attributes defined in one XML
> language can be used in another XML language.


>(from http://www.rpbourret.com/xml/NamespacesFAQ.htm#q5_3)



This quote suggests that, when designing a schema/DTD one can safely
let most (if not all) attributes have no namespace (i.e. be
"unprefixed"); during this design phase, only rarely need one
specify an attribute as belonging to a namespace (i.e. requiring
a prefix).

But I am interested in learning to recognize those rare situations
in which, as a designer, one *should* put a particular attribute
in a namespace. This is still very unclear to me. What are the
requirements that an attribute must fulfill to be a good candidate
for being placed in a namespace?

Thanks!

kj
--
NOTE: In my address everything before the period is backwards.

Victor Engmark 04-21-2004 12:47 PM

Re: Namespaces & prefixed attributes (one more time)
 
kj wrote:


> But I am interested in learning to recognize those rare situations
> in which, as a designer, one *should* put a particular attribute
> in a namespace. This is still very unclear to me. What are the
> requirements that an attribute must fulfill to be a good candidate
> for being placed in a namespace?


The one which comes to mind is where the attribute belongs to a
different namespace than that of the sorrounding element. This is
relevant e.g. when specifying that the "id" attribute should have the
properties of the special XML Schema "id" attribute (it has to be unique
in all the XML document):
<html:table title="Jack's finest recipies" xsd:id="recipies">
The "title" attribute doesn't need a namespace, because it is inferred
from the sorrounding element. The "id" attribute in this case does not
belong to the html namespace. Using xsd:id can be useful for validation
purposes.

--
Victor

C. M. Sperberg-McQueen 04-23-2004 05:35 PM

Re: Namespaces & prefixed attributes (one more time)
 
Victor Engmark <victor.engmark@cern.ch> writes:

> kj wrote:
>
> > ... What are the
> > requirements that an attribute must fulfill to be a good
> > candidate for being placed in a namespace?


> The one which comes to mind is where the attribute belongs
> to a different namespace than that of the sorrounding element.


This is true.

> This is relevant e.g. when specifying that the "id" attribute
> should have the properties of the special XML Schema "id"
> attribute (it has to be unique in all the XML document):


> <html:table title="Jack's finest recipies" xsd:id="recipies">


Er, I'm not sure this is right. The XML Schema namespace does not
define a top-level attribute named 'id'. It defines a top-level
simple type named ID (or xsd:ID, if you've bound the 'xsd' prefix to
"http://www.w3.org/2001/XMLSchema"), which requires its value to be
unique among the values of that type occurring in a document, just
like the ID attribute type of DTDs. But no top-level attribute.

There are occasional proposals for an xml:id attribute which would be
declared as having type xsd:ID -- indeed, the W3C XML Core Working
Group published a Working Draft proposing such an attribute just the
other day (http://www.w3.org/TR/2004/WD-xml-id-20040407/). If you
changed 'xsd:id' to 'xml:id' in the example above I think the usage
shown would be correct.


On the original question, one answer is simple: it makes sense to
define a top-level attribute when you can say what the attribute means
without any reference to the meaning or type of the element it appears
on. An attribute like 'xml:id' qualifies because its meaning
('provides an identifier which uniquely identifies the host element
within the document') can be described without any reference to the
name, type, or meaning of the host element.

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium




All times are GMT. The time now is 12:22 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.