An XML namespace gives the types defined in and XML schema a unique name - kind of like a sir name. In the US there are probably 10 million people named "John" so we use Sir names like "Smith" and middle names like "William" to distinguish one "John" from the next. You can think of element names as first names and XML namespaces as Sir names. (Its not a prefect analogy but it's illustrative).
Sometimes it's helpful to think of XML Namespaces as being similar to
Java package names. When you create an XML Schema you are defining a type, just as a Java source file defines a type. The targetNamespace is the unique namespace of that type, just like the package name of a class defintion is the unique namespace of that type. In other words, declaring a targetNamespace in an XML Schema is the same as declaring a package name in a Java class file. It assigns the type(s) to a particular namespace.
The concept of a default namespace and a targetNamespace are orthogonal; they are separate concepts.
The default namespace has scope. If you create an XML document (be it an instance document, WSDL file,
SOAP message or XML Schema) all of the elements are assumed to have unique namespaces. Usually, you will assign a prefix (a nick name) to each namespace and than tag elements that belong to that namespace with the prefix (e.g. <soap:Envelope>
. However, it is possible to create a default namespace, which is the same as saying any elements without a prefix belong to a certain namespace. A default namespace is simply a namespace that is declared without a preface (e.g. xmlns="http://www.blue.com"). Default namespaces apply to the element in which they are declared and all of its children that do not use an explicit prefix.
You can override a default namespace by assigning a child element a different default namespace (e.g. xmlns="http:\\www.red.com") - that element and its children that do not have an explicit prefix will become part of the new default namespace.
I hope that helps. Tried to give you a couple different ways of thinking of things.
Richard