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 11:51:48 +0100
Message-ID: <461372916779.20020828115148@jenitennison.com>
To: gino.marckx@belgacom.be
CC: xmlschema-dev@w3c.org

Hi Gino,

> I want to reuse the simpleType element definition we all use for
> defining our own schema's, in a schema. In other words, I want to be
> able in the XML document, using my schema, to define simpleType
> elements as data.
>
> Example:
> <types xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
>         <type name="myStringType" type="xsd:string"/>
>         <type name="myEnumerationBasedOnStringType">
>                 <xsd:simpleType>
>                         <!-- If the following is impossible, it could restrict xsd:string too -->
>                         <xsd:restriction base="myStringType">
>                                 <xsd:enumeration>Possible value</xsd:enumeration>
>                         </xsd:restriction>
>                 </xsd:simpleType>
>         </type>
> </types>

OK, so you want to say that the type element can contain a
xsd:simpleType element, as defined in the W3C XML Schema namespace.

> I tried to specify the type element like the following, but on
> validation I always get the same error stating that the type cannot
> be found, even when I import the schema:
>
> <xsd:element name="type">
>         <xsd:complexType>
>                 <xsd:sequence>
>                         <xsd:element name="simpleType" type="xsd:anySimpleType" minOccurs="0"/>
>                 </xsd:sequence>
>                 <xsd:attribute name="name" value="xsd:string"/>
>                 <xsd:attribute name="type" value="xsd:QName" use="optional"/>
>         </xsd:complexType>
> </xsd:element>

Here, you're saying that the type element can hold a simpleType
element (in your namespace or in no namespace, depending on the value
of elementFormDefault on your xsd:schema element). I think, from the
example that you've given, that you want it to hold a *xsd:simpleType*
element. To do that, you need to refer to the xsd:simpleType element
from the content model, as follows:

<xsd:element name="type">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element ref="xsd:simpleType" minOccurs="0"/>
    </xsd:sequence>
    <xsd:attribute name="name" value="xsd:string"/>
    <xsd:attribute name="type" value="xsd:QName" use="optional"/>
  </xsd:complexType>
</xsd:element>

To refer explicitly to an element in another namespace, you *must*
have an xsd:import element that references that namespace (although it
doesn't necessarily have to point to a schema). So you need:

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

or something similar at the top of your schema.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Wednesday, 28 August 2002 06:51:55 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:34 GMT