W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2002

Re: Reusing the XMLSchema simpleType element in an own schema

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 28 Aug 2002 12:24:51 +0100
Message-ID: <851374899180.20020828122451@jenitennison.com>
To: gino.marckx@belgacom.be
CC: xmlschema-dev@w3c.org

Hi Gino,

> I tried your suggestion this morning already and it did not do what
> I wanted. In the "http://www.w3.org/2000/10/XMLSchema", simpleType
> seems to be defined multiple times and I do not seem to be able to
> get the version I want. If I follow your suggestion, the schema
> forces me use the following structure in the data document:
>         <xsd:simpleType name="xxx">
>                 <xsd:simpleDerivation></xsd:simpleDerivation>
>         </xsd:simpleType>
> That is why I tried to solve it by mimicing how elements are defined
> in XMLSchema.

OK, two things.

First, why are you using the old "http://www.w3.org/2000/10/XMLSchema"
rather than "http://www.w3.org/2001/XMLSchema", which is the
Recommendation version? Whichever you use, you should make sure that
you're consistent with your use of namespaces -- if you try importing
a schema whose target namespace is
"http://www.w3.org/2000/10/XMLSchema" and importing it to provide
elements in the namespace "http://www.w3.org/2001/XMLSchema" then your
validator will complain about that.

Second, the schema for schema at http://www.w3.org/2001/XMLSchema.xsd
does declare the simpleType element globally, so you should be able to
refer to it directly. It's worth noting, however, that the global
declaration is meant for global simple type definitions (i.e. those
found at the top level of the schema) rather than local simple type
definitions, which are the kind that you want to use in your document.

If you want to have xsd:simpleType elements of the local type then you
should create an "adapter schema", with the W3C XML Schema target
namespace, which includes the schema for schema and defines a group
containing a xsd:simpleType element:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

<xsd:include schemaLocation="http://www.w3.org/2001/XMLSchema.xsd" />

<xsd:group name="localSimpleType">
    <xsd:element name="simpleType" type="xsd:localSimpleType" />


You can then import this adapter schema into your own, and declare
your type element as follows:

<xsd:import namespace="http://www.w3.org/2001/XMLSchema"
            schemaLocation="myAdapterSchema.xsd" />

<xsd:element name="type">
    <xsd:group ref="xsd:localSimpleType" minOccurs="0" />
    <xsd:attribute name="name" type="xsd:string" use="required" />
    <xsd:attribute name="type" type="xsd:QName" />

[Note that the name attribute has to be explicitly labelled as
required, while the type attribute declaration doesn't need a 'use'
attribute to indicate that it's optional, since attributes are
optional by default.]



Jeni Tennison
Received on Wednesday, 28 August 2002 07:24:53 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:05 UTC