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 Wednesday, 29 August 2001 20:15:05 UTC