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

Is it possible to specify a tag value or the attribute should not be like some_value ?

I have a strange requirement when xsd does not know what values ​​are sent to it. The value of this particular tag can be a string with any value except one value (say data_migration).

The sender must be acknowledged with an error if this particular value is sent.

Can this restriction be specified?

+3
source share
3 answers

, simpleType , data_migration .

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

, . , , , .

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

IncludedEnumType, CombinedEnumType. IncludedEnumType, , ExcludedEnumType.

2 IBM.

+2

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


All Articles