W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > April to June 2002

Re: Feature request - anonymous simplecontent type definition within complex type definition

From: Priscilla Walmsley <priscilla@walmsley.com>
Date: Fri, 28 Jun 2002 08:32:14 -0400
To: <www-xml-schema-comments@w3.org>
Message-ID: <000601c21e9f$d5ddc730$339afea9@WALMSLEYPH>

> Maybe I'm missing something, but can't you avoid this by doing
> like this

>  <xs:element name="foo">
>    <xs:complexType>
>     <xs:simpleContent>
>       <xs:restriction base="xs:anyType">
>         <xs:simpleType>
>           <xs:restriction base="xs:string">
>             <xs:maxLength value="8"/>
>           </xs:restriction>
>         </xs:simpleType>
>         <xs:attribute name="bar"/>
>       </xs:restriction>
>     </xs:simpleContent>
>   </xs:complexType>
> </xs:element>

Unfortunately that won't work because adding attributes is considered an
extension, not a restriction, and you can't do both in one step.

Michael, one way I've gotten around this in the past is by creating an
abstract complex type with simple content and an attribute wildcard and
just creating restrictions of it.  For example:

    <xs:complexType name="baseType" abstract="true">
       <xs:extension base="xs:string">

Then you can have element definitions like:

  <xs:element name="foo">
       <xs:restriction base="baseType">
         <xs:maxLength value="8"/>
         <xs:attribute name="bar"/>

But I agree that there is a usability issue here - this question comes
up a lot.


Priscilla Walmsley             priscilla@walmsley.com
Author, Definitive XML Schema     (Prentice Hall PTR)
Received on Friday, 28 June 2002 08:34:23 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:50:00 UTC