- From: Martin Gudgin <marting@develop.com>
- Date: Thu, 10 Aug 2000 11:11:05 +0100
- To: <www-xml-schema-comments@w3.org>
[inline]
----- Original Message -----
From: "Liz Castro" <lcastro@cookwood.com>
To: <www-xml-schema-comments@w3.org>
Sent: Thursday, August 10, 2000 2:36 AM
Subject: Re: namespaces and schemaLocation
> > Re: namespaces and schemaLocation
> >
> > From: Martin Gudgin (marting@develop.com)
> > Date: Wed, Aug 09 2000
> >
> > There are two problems. The main one is that your 'contents' element is
> > unqualified in the schema ( in 'no namespace' ) and qualified in the
> > instance ( in the
> > http://www.cookwood.com/ns/content namespace ).
> >
> > You can modify this by setting from='qualified' on the local element
> > declaration. Or you can modify it for an entire schema by specifying
> > elementFormDefault='qualified' on the schema element.
>
> 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?
[MJG]
Sorry, the tns prefix is a habit of mine. Whenever I write a schema I always
put in an xmlns:tns and then the targetNamespace attribute ( tns stands for
target name space ). You're right that I don't use it in the example and
therefore it could be removed.
Back to the way XSD works; it is the value of the targetNamespace attribute
that determines which namespace top level schema components are in ( named
types, global element decls, global attribute decls etc ). Namespace
declarations ( xmlns= xmlns:pre= etc ) have no effect on which namespace the
schema components belong to. They just allow us to refer to the schema
components. For example if I had a named type 'foo' in the namespace
'http://example.org/something' and I wanted to provide a global element
declaration I need someway of refering to foo in that namespace:
<schema xmlns='http://www.w3.org/1999/XMLSchema'
xmlns:tns='http://example.org/something'
targetNamespace='http://example.org/something' >
<complexType name='foo'>
<element name='bar' type='string' />
</complexType>
<element name='baz' type='tns:foo' />
</schema>
Note that in the above schema both 'foo' and 'baz' are in the
http://example.org/something namespace while 'bar' is in no namespace
because all local element and attribute decls are, by default, in no
namespace.
The schema below is equivalent, but I *never* write schemas this way. I
pretty much always map the default namespace to
http://www.w3.org/1999/XMLSchema:
<xsd:schema xmlns:xsd='http://www.w3.org/1999/XMLSchema'
xmlns='http://example.org/something'
targetNamespace='http://example.org/something' >
<xsd:complexType name='foo'>
<xsd:element name='bar' type='xsd:string' />
</xsd:complexType>
<xsd:element name='baz' type='foo' />
</schema>
>
> 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.
[MJG]
No, they are in different namespaces as defined by your schema because, as I
said in the previous mail, by default local element ( and attribute )
declarations are in no namespace. You can change this by putting
form='qualified' on the element declaration or by putting
elementFormDefault='qualified' on xsd:schema. The former just puts that
element into the target namespace while the latter puts all local element
decls into the target namespace ( assuming its not overridden by
form='unqualified' on a local element decl! )
>
> I have the feeling I'm going about this the wrong way. I have been reading
and rereading those
> specs, but I find them very hard to decipher. I hope these aren't terribly
stupid questions! And
> thanks so much for helping me through them.
[MJG]
I think the only thing that is tripping you up is the fact that by default
local element declarations are in no namespace rather than in the target
namespace. I would suggest that if in the general case you want all the
elements in an instance to be in the same namespace then you put
elementFormDefault='qualified' on your xsd:schema element:
<schema xmlns='http://www.w3.org/1999/XMLSchema'
xmlns:tns='http://example.org/something'
targetNamespace='http://example.org/something'
elementFormDefault='qualified' >
<complexType name='foo'>
<element name='bar' type='string' />
</complexType>
<element name='baz' type='tns:foo' />
</schema>
With the above schema foo, bar and baz are all in the target namespace.
>
> >
> >
> > 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).
[MJG]
That's an error on XML Spy's part. The relevant part of the spec is under
Constraint on Schemas: xsi: not allowed in[1]
Regards
Martin Gudgin
DevelopMentor
[1] http://www.w3.org/TR/xmlschema-1/#coss-attribute
Received on Thursday, 10 August 2000 06:12:46 UTC