The specification of XML Namespaces explains that the interpretation of unprefixed attributes is determined by the element on which they appear. And that the namespace name for an unprefixed attribute name always has no value.
How does this rule apply to the namespace of the attribute jid
in the following cases.
<query xmlns="jabber:iq:roster">
<item jid="romeo@example.com"></item>
</query>
If the declaration of the namespace and the attribute in question both don't have an prefix, the attribute jid
is in the namespace jabber:iq:roster
.
<q:query xmlns:q="jabber:iq:roster">
<q:item q:jid="romeo@example.com"></q:item>
</q:query>
If both, the declaration of the namespace and the attribute have the same prefix, the attribute jid
also has the namespace jabber:iq:roster
:
<q:query xmlns:q="jabber:iq:roster">
<q:item jid="romeo@example.com"></q:item>
</q:query>
But in which namespace is the attribute if the namespace is declared with an prefix but the attribute doesn't have a prefix? I would assume, that the attribute jid
has the default namespace declared in a parent element,
<parent xmlns="http://example.com"> <q:query xmlns:q="jabber:iq:roster"> <q:item jid="romeo@example.com"></q:item> </q:query> </parent>
- or no namespace, if there isn't such a declaration.
Do I get this right?
An attribute without prefix is always in the empty name space, i.e. it has no name space. It is doesn't matter whether the enclosing element has a name space or not. That's my reading of the second statement you refer to, and that is the interpretation of all the XML tools I've used.
The normal interpretation used by XPath and other specs is that an unprefixed attribute is in no namespace.
There are language lawyers who will insist that the namespaces spec doesn't say that. It says that an unprefixed attribute is in whatever namespace the designer of the vocabulary says it is in. But this interpretation isn't very useful in practice; it's what the tools do that matters.