RE: Always use complexType/simpleContent/restriction?

Hello Eddi,

thanks for your reply. 
I understand now that from a base type you cannot "add" an attribute by
restriction, because the base type does not has this attribute before. 
And you cannot restrict a base type with a facet by complexType, because the
result is not a complex, but a simple type and thus simpleType has to be
used.

So the solution is named types.

Kind regards,
Harald


-----Original Message-----
From: Eddie Robertsson [mailto:eddie@allette.com.au]
Sent: Thursday, August 30, 2001 2:14 AM
To: Lemmin, Harald
Cc: xmlschema-dev@w3.org
Subject: Re: Always use complexType/simpleContent/restriction?


Hi Harald,

> I automatically generate schemata and can use only simple types, but no
> named types.
> I want to model:
> (a) an element (simple type) with an attribute.

 <xs:element name="a">
  <xs:complexType>
   <xs:simpleContent>
    <xs:extension base="xs:string">
     <xs:attribute name="a" type="xs:string"/>
    </xs:extension>
   </xs:simpleContent>
  </xs:complexType>
 </xs:element>

> (b) an element (simple type) with a facette.

 <xs:element name="b">
  <xs:simpleType>
   <xs:restriction base="xs:string">
    <xs:length value="10"/>
   </xs:restriction>
  </xs:simpleType>
 </xs:element>

> (c) an element (simple type) with an attribute and a facette.
>
> (c) can be modelled only with complexType/simpleContent/restriction:
>         <element name="e" type="xs:string">
>           <complexType>
>             <simpleContent>
>               <restriction>
>                 <length value="10"/>
>                 <attribute name="a" type="xs:string">
>                 </attribute>
>               </restriction>
>             </simpleContent>
>           </complexType>
>         </element>

I don't think you can do c) without using named type but I'm not 100% sure.
The
example you give above is not valid because 1) you can't use both the type
attribute and the child element <complexType>, 2) If you want to add an
attribute to a simpleContent model you have to use <extension> and not
restriction.

> My questions are:
> (I) Which solution to use in case (a) and (b)? Can I always use
> complexType/simpleContent/restriction, like (c)??

See solution above.

> (II) Is it ok to "restrict" an element (simple type) by an attribute, like
> done in (c) [shouldn't it be an extension]? If not, how to model (c)
without
> named types?

No, you have to use extension and I can't see how you can model (c) without
named types.

Cheers,
/Eddie

Received on Thursday, 30 August 2001 06:28:34 UTC