W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2001

RE: how to constraint sinmpleTypes

From: Ayalew Kassahun <A.Kassahun@InfoRay.NL>
Date: Wed, 31 Jan 2001 10:39:10 +0100
Message-ID: <7FAFD1931B62D411B2890050BAB19FB137E2B5@ms1.inforay.nl>
To: xmlschema-dev@w3.org
Cc: Michael Anderson <michael@research.canon.com.au>
Hi List, Mick,

None of the three scenarios are answer to my question. My question is that I
want to specify in the schema that the allowed simple times (not only for
age but for all simple types in my docs) are xsd:int, xsd:string or
xsd:data. If there is anything which is of a simpleType then it must be one
of the above three types.

I was think of in this lines:

In my schema ...

<xsd:simpleType name="mySimpleType">
  <xsd:simpleType>
    <xsd:union memberTypes="xsd:short xsd:integer xsd:double"/>
  </xsd:simpleType>
</xsd:simpleType>

then I want to use mySimpleType for whatever simple type ...

In my docs, for example:

<!-- age is a mySimpleType, it can be given as int, double or as string -->
<xsd:element name="age">
  <myNS:mySimpleType>
  </xsd:simpleType>
</xsd:element>

<!-- weight is a mySimpleType, it can only be a double -->
<xsd:element name="weight">
  <myNS:mySimpleType>
	<xsd:restriction base="xsd:double"/>
  </xsd:simpleType>
</xsd:element>

I am not sure if simpleType itself can be redefined with some restriction.
Can somebody tell me the  right way of doing this.

<!-- etc etc -->

Ayalew

> 
> Ayalew Kassahun wrote:
> 
> > Hi List:
> >
> > I have (what seams to me) a simple question but I 
> difficulty expressing it
> > in my schema. I want to constraint users of my schema to 
> use only a subset
> > of the simpleTypes: xsd:int, xsd:double and xsd:string. How 
> can I specify
> > that in my schema?
> >
> > For example in the following document I want the element <age
> > type="xsd:short">23</age> be reported as 'invalid' because 
> its content is of
> > type short.
> >
> > <?xml version="1.0"?>
> > <purchaseOrder orderDate="1999-10-20">
> >     <shipTo country="US">
> >         <name>Alice Smith</name>
> >         <age type="xsd:short">23</age>
> >         <city>Mill Valley</city>
> >         <state>CA</state>
> >         <zip>90952</zip>
> >     </shipTo>
> >     <billTo country="US">
> >         <name>Robert Smith</name>
> >         <street>8 Oak Avenue</street>
> >         <city>Old Town</city>
> >         <state>PA</state>
> >         <zip>95819</zip>
> >     </billTo>
> > </purchaseOrder>
> >
> > any suggestion is welcome.
> >
> > regards
> > Ayalew
> 
> I'm not exactly sure what you want to do, so here are three solutions.
> 1. If you want age to _only_ be a short and you want to 
> specify this in the
> instance, then you can use the following for the instance:
> <purchaceOrder orderDate = "1999-10-20"
> 
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
>                         
> xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
> <snip/>
> <age xsi:type="xsd:short">23</age>
> <snip/>
> 
> 2. If you want age to _only_be a short and you want to 
> specify this in the
> schema, then you can use the following in the schema:
> <xsd:element name="age" type="xsd:short"/>
> where xsd is defined as in case 1.
> Now your instance will be valid with <age>23</age> but 
> invalid with <age>hello
> world</age>
> 
> 3. If you want age to be a short OR integer OR double, then 
> in your schema you
> use a union
> <xsd:element name="age">
>   <xsd:simpleType>
>     <xsd:union memberTypes="xsd:short xsd:integer xsd:double"/>
>   </xsd:simpleType>
> </xsd:element>
> Now your instance will be valid with <age>23</age> AND 
> <age>23.4</age> but
> invalid with <age>hello world</age>
> 
> For a better explanation than mine, see the primer [1]
> 
> mick.
> 
> [1] http://www.w3.org/TR/xmlschema-0/#CreatDt
> 
> 
> 
> 
Received on Wednesday, 31 January 2001 04:26:38 GMT

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