W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > July to September 2000

Re: namespaces and schemaLocation

From: Ace <Ace@AceProgrammer.com>
Date: Wed, 09 Aug 2000 21:57:15 -0700
Message-ID: <3992362B.EDC2BFEB@AceProgrammer.com>
To: www-xml-schema-comments@w3.org
> I guess there's something else I'm not getting. In your new schema, you declared the "tns"
> prefix but never used it. I thought if you declared a namespace with xmlns="url" then that
> namespace was the default. But you're saying that my content declaration was in "no namespace"
> (and not in the default namespace as I intended). How can that be? And how can it be solved by
> declaring a namespace with a prefix but never using that prefix?

Many examples start out with
<schema xmlns="http://www.w3.org/1999/XMLSchema"
which basically says set the default namespace to "XMLSchema".  Doing this eliminates the need to
qualify all of the schema elements.  If you associate a prefix with this namespace, you'll need to
use that prefix with all of the elements defined in that namespace.  Notice that in the following
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema"
the "XMLSchema" namespace is associated with the prefix "xsd".  Because the "schema" element
(<schema> </schema>) is defined within the "XMLSchema" namespace, and it is associated with "xsd"
you need to qualify it as well:
As an earlier post pointed out, you could do the following (if you were so inclined):
<BOB:schema xmlns:BOB="http://www.w3.org/1999/XMLSchema">

In the example, the line
is actually not needed, unless you needed to define more elements within the "contents" namespace.
For example...

<xsd:element name="test">
  <xsd:complexType content="elementOnly">
      <xsd:element name="contents" type="xsd:string" />
      <xsd:element name="aLocalElement" type="tns:localType" />

<xsd:simpleType name="localType" base="string">
  <xsd:maxLength value="50" />

In this case, both "localType" and "test" items are defined in the "contents" schema, because of the
targetNamespace entry:
Without this attribute, all locally defined items are defined in the "no namespace".

> In the XML document, it looks like you again add a prefix ("p" this time) and use it only for
> test, not for content. Aren't test and contents part of the same namespace? And if not, how did
> that happen. Certainly, my intention was to create one particular namespace with both elements
> in it, and then to use those elements in an instance.

Schema is an xml doc, the same as yours.  The same rules apply:

<p:test xmlns:p="http://www.cookwood.com/ns/contents"
This line says that the element "test" is defined in the namespace associated with the prefix "p"
(in this case "p" is associated with "contents").

xsi:schemaLocation="http://www.cookwood.com/ns/contents http://marting.develop.com/xsd/simple.xsd">
The "Schema-instance" schema is associated with the "xsi" prefix, and the schemaLocation attribute
is defined in that same namespace.

  <contents>this is the contents</contents>
The contents element needs no qualifier because it is an element locally defined within the "test"

> > The second problem is that it is illegal to have declarations for attributes
> > in the http://www.w3.org/1999/XMLSchema-instance namespace.
> Also curious. Those were added automatically by XML Spy and I thought that they were necessary
> (and legal).

Sorry, I must admit a bit of confusion myself in this area.  I don't quite understand how I can
specify an attribute "xmlns:xsi" on the test element when it wasn't defined.  My guess is that it
has something to do with the fact that test is the root element, and the namespace specification
says something to the effect of "if this is the root element, it has some implicitly defined
attributes available."

Hope this helps,

Received on Thursday, 10 August 2000 00:55:01 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:49:53 UTC