Create an XSD optional decimal element with restrictions

二次信任 提交于 2019-12-05 19:25:53

Thanks to Kevin's suggestion I've come up with this which does the trick:

  <xs:simpleType name="Decimal10-2">
    <xs:restriction base="xs:decimal">
      <xs:maxInclusive value="9999999999"/>
      <xs:fractionDigits value="2"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="OptionalDecimal10-2">
    <xs:union memberTypes="Decimal10-2 empty-string" />
  </xs:simpleType>

you must use a "choice" element: look this

<xsd:simpleType name="OptionA">
    <xsd:restriction base="xsd:string">
        <xsd:length value="11" fixed="true"/>
    </xsd:restriction>
</xsd:simpleType>


<xsd:simpleType name="OptionB">
    <xsd:restriction base="xsd:string">
        <xsd:length value="14" fixed="true"/>
        <xsd:whiteSpace value="collapse"/>
    </xsd:restriction>
</xsd:simpleType>


<xsd:complexType name="MyField">
    <xsd:choice>
        <xsd:element name="OptA" type="OptionA" minOccurs="1" maxOccurs="1"/>
        <xsd:element name="OptB" type="OptionB" minOccurs="1" maxOccurs="1"/>
    </xsd:choice>
</xsd:complexType>

Best regards, Dan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!