开发者

How can I extend restrictions on simple type element?

开发者 https://www.devze.com 2022-12-30 03:49 出处:网络
Could somebody post an example about how to add enu开发者_如何学Gomerated restriction on simpletype element in xml schema?<xs:simpleType name=\"myElement\">

Could somebody post an example about how to add enu开发者_如何学Gomerated restriction on simpletype element in xml schema?


  <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>


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消