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

RE: Confusion about SimpleContent and SimpleType restrictions

From: Priscilla Walmsley <priscilla@walmsley.com>
Date: Fri, 7 Dec 2001 13:27:26 -0500
To: "'Niko Suave'" <niko@alum.mit.edu>, <xmlschema-dev@w3.org>
Message-ID: <000001c17f4c$e10f4180$658ace0a@vitria.ad.vitriacorp.com>
Hi Niko,

You can only have either a base attribute or a simpleType child, not both.
(Except in an obscure case when you are restricting mixed content to simple
content.)  So, your example is invalid for that reason.  Also, the embedded
simpleType would not have a name attribute.

The simpleType child is useful is if you are defining a list type and you
want to restrict it in some way.  For example, if you want a 3-item list of
integers, you can do it in one step:


  <xs:simpleType name="listOf3Integers">
    <xs:restriction>
      <xs:simpleType>
        <xs:list itemType="xs:integer"/>
      </xs:simpleType>
      <xs:length value="3"/>
    </xs:restriction>
  </xs:simpleType>

instead of having to do it in two steps:

  <xs:simpleType name="listOfIntegers">
    <xs:list itemType="xs:integer"/>
  </xs:simpleType>

  <xs:simpleType name="listOf3Integers">
    <xs:restriction base="listOfIntegers">
      <xs:length value="3"/>
    </xs:restriction>
  </xs:simpleType>


Priscilla
-----------------------------------------------------------
Priscilla Walmsley                   priscilla@walmsley.com
Vitria Technology                     http://www.vitria.com
Author, Definitive XML Schema    (Prentice Hall, Dec. 2001)
-----------------------------------------------------------

> -----Original Message-----
> From: xmlschema-dev-request@w3.org
> [mailto:xmlschema-dev-request@w3.org]On Behalf Of Niko Suave
> Sent: Friday, December 07, 2001 12:41 PM
> To: xmlschema-dev@w3.org
> Subject: Confusion about SimpleContent and SimpleType restrictions
>
>
> I don't understand why simple restrictions (both simpleType
> and simpleContent)
> allow a "simpleType" to be specified within them.
>
> i.e., simpleContent looks like this:
>
> <restriction
>   base = QName
>   id = ID
>   {any attributes with non-schema namespace . . .}>
>   Content: (annotation?, (simpleType?, <facets>*)?,
>                          ((attribute | attributeGroup)*,
> anyAttribute?))
> </restriction>
>
>
> So if I do something like this:
>
> <xs:complexType name="base">
>   <xs:simpleContent>
>     <xs:extension base="xs:string">
>       <xs:attribute name="x" type="xs:decimal"/>
>     </xs:extension>
>   </xs:simpleContent>
> </xs:complexType>
>
> <xs:complexType name="extended">
>   <xs:simpleContent>
>     <xs:restriction base="base">
>       <xs:simpleType name="embedded">
>         <xs:restriction base="xs:decimal">
>           <xs:totalDigits value="2"/>
>           <xs:fractionDigits value="2"/>
>         </xs:restriction>
>       </xs:simpleType>
>       <xs:fractionDigits value="1"/>
>     </xs:restriction>
>   </xs:simpleContent>
> </xs:complexType>
>
>
> is this valid?  what does this mean?  It's clear from the spec that
> the Base Type for "extended" is still formally the complex
> type "base"
> that I defined earlier.  However, the content model is based
> purely on the
> "embedded" simple type, which I suppose must still be a valid
> restriction of
> the formal base type.
>
> Based on this, I'd say this particular example is invalid b/c
> the "embedded"
> simple type is a xs:decimal, which is not a restriction of
> the simple type
> of "base" (xs:string), right?  If I changed the embedded
> simpleType to be a
> restriction of string and likewise changed the facets to
> other things,
> would it then be valid?  So why include this embedded
> simpleType at all,
> since essentially it just lets me add another layer of facets?
>
> I must be missing something.
>
>
> thanks,
> niko
>
>
Received on Friday, 7 December 2001 13:28:34 GMT

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