Xml schema: empty targetNamespace

xmlxsd

Is it legal to use no targetNamespace attribute or an empty one in an Xml schema?

If so then what does it mean, are we "adding" something to the "empty namespace" (which always exists) or creating an "anonymous namespace" which is not related to other schemas?

How would an instance xml document look like, do elements need to be explicitly bounded to some namespace?

Best Answer

See XML Schema Part 0: Primer for a very concise description of how undeclared targetNamespaces work.

As for an empty targetNamespace, that's not valid. From the spec:

Since the empty string is not a legal namespace name, supplying an empty string for targetNamespace is incoherent, and is not the same as not specifying it at all. The appropriate form of schema document corresponding to a ·schema· whose components have no {target namespace} is one which has no targetNamespace attribute specified at all.