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

> Maybe I'm missing something, but can't you avoid this by doing
something 
> 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:simpleContent>
       <xs:extension base="xs:string">
         <xs:anyAttribute/>
       </xs:extension>
     </xs:simpleContent>
   </xs:complexType>

Then you can have element definitions like:

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

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

Thanks,
Priscilla


-----------------------------------------------------
Priscilla Walmsley             priscilla@walmsley.com
Author, Definitive XML Schema     (Prentice Hall PTR)
----------------------------------------------------- 

Received on Friday, 28 June 2002 08:34:23 UTC