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

Re: restrictions of a complextype element

From: Eddie Robertsson <eddie@allette.com.au>
Date: Thu, 21 Jun 2001 17:50:00 +1000
Message-ID: <3B31A728.4FE3912A@allette.com.au>
To: David Valera <David.Valera@tridion.com>
CC: xmlschema-dev@w3.org
Hi David,

David Valera wrote:

> Hello,
>
> I am trying to restrict the value space of an element like this:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>  <xsd:element name="Test">
>    <xsd:complexType>
>     <xsd:simpleContent>
>         <xsd:restriction base="xsd:string">
>           <xsd:enumeration value="hello world"></xsd:enumeration>
>           <xsd:enumeration value="this is me"></xsd:enumeration>
>         </xsd:restriction>
>     </xsd:simpleContent>
>     <xsd:attribute name="myAtt" type="xsd:string"></xsd:attribute>
>    </xsd:complexType>
>  </xsd:element>
> </xsd:schema>
>
> The important part here is that I want to restrict an element which also has
> attributes. Is this example correct?

Not really. To achieve what you try to do you first need to create a global
simpleType for your base type like this:

<xs:simpleType name="enumType">
   <xs:restriction base="xsd:string">
      <xs:enumeration value="hello world"/>
      <xs:enumeration value="this is me"/>
   </xs:restriction>
</xs:simpleType>

When you have done this you can extend your complexType based on this enumType
by adding an attribute:

<xsd:element name="Test">
   <xsd:complexType>
      <xsd:simpleContent>
         <xsd:extension base="enumType">
            <xsd:attribute name="myAtt" type="xsd:string"></xsd:attribute>
         </xsd:extension>
      </xsd:simpleContent>
   </xsd:complexType>
</xsd:element>

Cheers,
/Eddie
Received on Thursday, 21 June 2001 03:48:56 GMT

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