RE: Reusing the XMLSchema simpleType element in an own schema

Hi Jeni,

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.

But thanks anyway,
Gino.

-----Original Message-----
From: Jeni Tennison [mailto:jeni@jenitennison.com]
Sent: 28 August 2002 12:52
To: gino.marckx@belgacom.be
Cc: xmlschema-dev@w3c.org
Subject: Re: Reusing the XMLSchema simpleType element in an own schema


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/

**** DISCLAIMER **** 
"This e-mail and any attachments thereto may contain information 
which is confidential and/or protected by intellectual property 
rights and are intended for the sole use of the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, 
total or partial reproduction, communication or distribution in any form) 
by persons other than the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either 
by telephone or by e-mail and delete the material from any computer. 
Thank you for your cooperation."

Received on Wednesday, 28 August 2002 07:00:43 UTC