1. Make XMLSchema the default namespace, and explicitly qualify all references to components in the targetNamespace.
2. Vice versa - make the targetNamespace the default namespace, and explicitly qualify all components from the XMLSchema namespace.
3. Do not use a default namespace - explicitly qualify references to components in the targetNamespace and explicitly qualify all components from the XMLSchema namespace.
Let's look at each approach in detail.
There is a namespace prefix, lib, which is associated with the targetNamespace. Any references (using the "ref" attribute) to components in the targetNamespace (Library, BookCatalogue, Book, etc) are explicitly qualified with lib (in this example there is a ref to lib:Book).
Advantages:
Clean design: there aren't many namespace qualifiers to clutter up the schema. So, the schema is quite readable.
Disadvantages:
For teaching purposes (or in doing a design review) we oftentimes want to focus on just a snippet of the schema. When examined outside the context of the entire schema, the namespace qualifier is often a source of confusion. For example, when this snippet is considered on its own:
It is the editor's experience that the namespace qualifier (lib) is frequently a source of confusion.
There is a default namespace declaration that declares the targetNamespace to be the default namespace. Any references to components in the targetNamespace are not namespace qualified (note that the ref to Book is not namespace qualified).
Advantages:
For teaching purposes (or in doing a design review) we oftentimes want to focus on just a snippet of the schema. It is generally easier to understand a snippet when there is not a qualifier on references to targetNamespace components
Disadvantages:
Cluttered design: there are a lot of namespace qualifiers being used. So, the schema is a bit less readable.
Advantages:
Very explicit: there are no implied (default) namespaces. Everything (all components and all references to components) is explicitly qualified.
Disadvantages:
Very cluttered: being very explicit by namespace qualifying everything can be annoying when reading the schema.
Editor's Note: At least when starting to learn XML Schemas it has been my experience that Approach 2 (Qualify XMLSchema, default targetNamespace) makes the schemas easiest to understand. The reason for this is:
- Qualifying the components that are used to construct a schema (schema, element, complexType, sequence, etc) is typically not a source of confusion since the qualifier is always the same (I always use xsd). That is, people get used to seeing xsd:schema, xsd:element, etc.
- On the other hand, the targetNamespaces may vary widely among schemas. Consequently, the namespace prefixes that one might generate can vary widely. For example, lib:Book, boston:subway. This variability is oftentimes a source of confusion.