How can I extend the restrictions to a simple type element?

Can someone post an example on how to add an enumerated restriction on a simpletype element in an xml schema?

+3
source share
2 answers
  <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>
+3
source

In this example, the element fruitmust 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 true:

<fruit>banana</fruit>

but this is not so:

<fruit>kumquat</fruit>
+1
source

Source: https://habr.com/ru/post/1745533/


All Articles