views:

49

answers:

1

When validating an xml document using xml-Schema and namespaces, the instance document has to have its global element prefixed with a namespace to qualify it, besides declaring the namespace itself.

One would think that a default namespace would suffice in this case to qualify the element, but xml-Schema apparently has another opinion.

Why is that? What is it about default namespaces that the xml-Schema just can't cope with?

+1  A: 

I believe this is by design to support Chameleon Namespace and to Avoid Name Collisions of Chameleon Components. In that I mean that by not providing a namsepace we default to a Chameleon design. However, when you do not provide the targetNamspace as the default namspace you will end up with a problem and error.

Note: Some Content Excerpted from XFront.com

A collectively Developed Set of Schema Design Guidelines

Here are your rules in general: Except for no-namespace schemas, every XML Schema uses at least two namespaces - the targetNamespace and the XMLSchema namespace. There are three ways to design your schemas, with regards to dealing with these two namespaces:

  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.

There really isn't a best practice with regards to which approach is correct. Primarily, it is all up to the designer.

Though, in my research I have found: - Qualifying the components that are used to construct a schema (schema, element, complexType, sequence, etc) are typically not a source of confusion since the qualifier is always the same. 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 often times a source of confusion.

I hope this answers your question.

Joe Garrett
Nica answer Joe. If this will be approved as the right one (by Oskar) you'll get the bounty on tuesday. I'll be away and disconnected from internet the coming four days. BR -
BennySkogberg