Namespaces were introduced into XML to avoid name clashes when multiple vocabularies are used. The concept of namespaces allows us to mix language elements from multiple vocabularies, such as SVG and XHTML, by adding namespace prefixes. It also allows us to define schemas with XML Schema, because by using namespace prefixes we can separate XML Schema tags and our own element names.
Namespace identifiers must be globally unique - usually a
URI is used for that purpose. Defining a namespace within
an XML document is simple: a document node is given an xmlns
attribute to define the default namespace. Similarly,
additional namespaces can be introduced by defining namespace prefixes using
namespace declaration attributes of the form
xmlns:prefix=URI
.
The scope of such a definition is the node where it is defined plus all child
nodes (child elements and attributes), unless a child element overrides it with
another namespace declaration. So, if we declare namespaces in a document's
root element, their scope is usually the whole document.
The most important difference between TSD4 andTSD3 is that TSD4 supports XML Namespaces. This section explains why and how you should use namespaces.
Note:
TSD3 and TSD4 make use of that separation feature to differentiate
between XML Schema parts that are marked with the xs:
prefix, and
the Tamino-specific extensions that are marked with the tsd:
prefix.
The name of an element or attribute is called "qualified"
if it contains a prefix and is within the
scope of a corresponding namespace declaration. In addition, only elements
without a prefix are affected by the default namespace declaration. The lexical
(or pseudo) QName - an abbreviation of qualified name - is
just the name string
prefix:localname
.
The prefix including the colon is optional. See
XML Schema, Part 2. The
expanded (or standard) QName is the associated "tuple" (URI, local
name) derived from the QName and the namespace declaration for the prefix. For
an unqualified name, the URI part of this "tuple" is empty.
Let us start with a definition of the terms for QNames (qualified names):
- [expanded or standard] QName:
An expanded QName or standard QName is a tuple
(URI,localName)
which may also be derived from a stringprefix:localName
in conjunction with a namespace declaration likexmlns:prefix=URI
or a namespace context (see below).For unqualified elements or attributes the URI may be empty.
- [pseudo or lexical] QName:
A pseudo QName or lexical QName is a string
prefix:localName
without a namespace context or declaration . The prefix may be empty.