tags:

views:

17

answers:

2

Hi all,

Could somebody post an example about how to add enumerated restriction on simpletype element in xml schema?

+1  A: 

In this example, the fruit element must be a string whose value is in the set {"apple", "banana", "coconut"}.

<xs:element name="fruit">
  <xs:simpleType>
   <xs:restriction base="xs:string">
      <xs:enumeration value="apple"/>
      <xs:enumeration value="banana"/>
      <xs:enumeration value="coconut"/>
   </xs:restriction>
  </xs:simpleType>
</xs:element>

So, this is valid:

<fruit>banana</fruit>

but this is not:

<fruit>kumquat</fruit>
John Feminella
+1  A: 
  <xs:simpleType name="myElement">
    <xs:union memberTypes="previousRestrictions">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="close" />
        </xs:restriction>
      </xs:simpleType>
    </xs:union>
  </xs:simpleType>
Leslie Norman
Thank you JSteve, it works
WSK