Namespaces & prefixed attributes (one more time)

K

kj

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.


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
 
V

Victor Engmark

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.
 
C

C. M. Sperberg-McQueen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top