How to exclude an enumeration value in XML file using XSD?

▼魔方 西西 提交于 2019-12-01 22:48:24
Jens Granlund

I'm no regex expert, but this simpleType makes everything starting with data_migration invalid.

<xs:simpleType name="notDataMigration">
  <xs:restriction base="xs:string">
    <xs:pattern value="^(?!data_migration).*" />
  </xs:restriction>
</xs:simpleType>
Ryan

I don't know if you can specifically exclude a value. I'm not sure if this helps, but you can create two separate enumerations and then create the union of the enumerations.

<xsd:simpleType name="IncludedEnumType">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="pending" />
    <xsd:enumeration value="in_process" />
    <xsd:enumeration value="failed" />
    <xsd:enumeration value="unknown" />
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="ExcludedEnumType">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="data_migration" />
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="CombinedEnumType">
  <xsd:union memberTypes="IncludedEnumType ExcludedEnumType" />
</xsd:simpleType>

You would use either IncludedEnumType or CombinedEnumType as necessary. Using the IncludedEnumType would obviously excluded the values in ExcludedEnumType.

This approach uses Solution 2 from this article by IBM.

Use regular expressions to specify a pattern or as in your case what a pattern should not contain.

http://www.w3schools.com/schema/schema_facets.asp

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