Per the spec, you are correct to consider the namespace of the attrib
in the first example to be empty. However, there is a subtlety here that may not be readily obvious.
Consider this example further down in the spec of an element with two attributes with the same name (one prefixed and another unprefixed).
<!-- This is OK, even though an element cannot have two attributes
with the same name -->
<x xmlns:n1="http://www.w3.org"
xmlns="http://www.w3.org" >
<good a="1" n1:a="2" />
</x>
This is conformant because the two attributes are indeed in two different namespaces:
n1:a
belongs to http://www.w3.org
namespace (which is the namespace of good
as well)
a
is treated to belong to an inaccessible namespace http://wwww.w3.org > good
(and different from the namespace of good
).
Note that http://wwww.w3.org > good
namespace does not exist; for example, you cannot query for attributes in this namespace with XPath. If you ask for namespace-uri(\\good\a)
, it will be empty. To make the idea of a separate element namespace concrete, I made up a namespace that has both the element namespace and name together with a separator (>
is not allowed unescaped in attribute values anyways).
Now, instead of saying that the two attributes are in two different namespaces, it is more correct to say that they belong to two different namespace partitions:
n1:a
attribute belongs to the Global Attribute Partition (http://www.w3.org
)
good
element belongs to All Element Types Partition (also http://www.w3.org
)
a
belongs to the Per Element Type Partition Of good
(i.e., http://wwww.w3.org > good
).
Here's the relevant part of the spec Porges linked to:
A.2 XML Namespace Partitions
In order to support the goal of making both qualified and unqualified
names useful in meeting their intended purpose, we identify the names
appearing in an XML namespace as belonging to one of several disjoint
traditional (i.e. set-structured) namespaces, called namespace
partitions. The partitions are:
The All Element Types Partition All element types in an XML namespace appear in this partition. Each has a unique local part; the
combination of the namespace name and the local part uniquely
identifies the element type.
The Global Attribute Partition This partition contains the names of all attributes which are defined, in this namespace, to be global.
The only required characteristic of a global attribute is that its
name be unique in the global attribute partition. This specification
makes no assertions as to the proper usage of such attributes. The
combination of the namespace name and the attribute name uniquely
identifies the global attribute.
The Per-Element-Type Partitions Each type in the All Element Types Partition has an associated namespace in which appear the names of the
unqualified attributes that are provided for that element. This is a
traditional namespace because the appearance of duplicate attribute
names on an element is forbidden by XML 1.0. The combination of the
attribute name with the element's type and namespace name uniquely
identifies each unqualified attribute.
In XML documents conforming to this specification, the names of all
qualified (prefixed) attributes are assigned to the global attribute
partition, and the names of all unqualified attributes are assigned to
the appropriate per-element-type partition.
<foo:child />
is the 'namespace' for@attrib
" then I would not need to add additional prefixes to provide the namespace. In other words, it would be unqualified which would be interpreted as being in whatever namespace the element is using. Is that correct? This would imply to me that my first example is in fact an okay way to write this. – Sheree