An attribute can appear in a different namespace than the element that contains it. For example,
<movie:title xml:lang="fr">
has an attribute that is not from the movie
namespace. If an attribute name has a prefix, its name is in the namespace indicated by the prefix. However, if an attribute name has no prefix, it has no namespace. This is true even when the default namespace has been assigned. The W3C Namespaces in XML Recommendation makes that point with this example:<x xmlns="http://www.w3.org" xmlns:n1="http://www.w3.org"> |
The elements are affected by the declaration of a URI for the default namespace. That is, both
x
and good
are associated with the URI "http://www.w3.org" because it's the default namespace. The attribute n1:a
is also associated with that namespace, due to its use of the n1
prefix, which is associated with the same URI. There is no conflict that the a
attribute is being declared twice, because while n1:a
is in the http://www.w3.org
namespace, the unprefixed a
is not; the latter is not in any namespace.