3.4 Undeclared Target NamespacesUndeclared Target Namespaces
In [Basic Concepts: The Purchase Order] we explained the basics of
XML Schema using a schema that did not declare a target
namespace and an instance document that did not declare a
namespace. So the question naturally arises: What is the
target namespace in these examples and how is it
referenced?
In the purchase order schema,
po.xsd, we did not declare a target namespace
for the schema, nor did we declare a prefix (like
po: above) associated with the schema's target
namespace with which we could refer to types and elements
defined and declared within the schema. The consequence of
not declaring a target namespace in a schema is that the
definitions and declarations from that schema, such as
USAddress and purchaseOrder, are
referenced without namespace qualification. In other words
there is no explicit namespace prefix applied to the
references nor is there any implicit namespace applied to
the reference by default. So for example, the
purchaseOrder element is declared using the type
reference PurchaseOrderType. In contrast, all
the XML Schema elements and types used in po.xsd are explicitly qualified with
the prefix xsd: that is associated with the
XML Schema namespace.
In cases where a schema is designed without a target namespace, it is
strongly recommended that all XML Schema elements and types are explicitly
qualified with a prefix such as xsd: that is associated
with the XML Schema namespace (as in po.xsd). The rationale for this recommendation is
that if XML Schema elements and types are associated with the XML Schema
namespace by default, i.e. without prefixes, then references to XML
Schema types may not be distinguishable from references to user-defined
types.
Element declarations from a schema with no target
namespace validate unqualified elements in the instance
document. That is, they validate elements for which no
namespace qualification is provided by either an explicit
prefix or by default (xmlns:). So, to validate
a traditional XML 1.0 document which does not use
namespaces at all, you must provide a schema with no target
namespace. Of course, there are many XML 1.0 documents that
do not use namespaces, so there will be many schema
documents written without target namespaces; you must be
sure to give to your processor a schema document that
corresponds to the vocabulary you wish to validate.
|