Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow only certain string at XML tag with XSD

I search for a way to check with my xsd that, a certain tag only one of different allowed strings contains.

E.g. two allowed strings are:

  • Index
  • Condition

OK:

<TYPE>Index</TYPE>
<TYPE>Condition</TYPE>

WRONG:

<TYPE>Integer</TYPE>

The definition from type in my xsd is as follows:

  <xs:element name="TYPE">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:minLength value="1"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
like image 877
dot Avatar asked Sep 14 '25 10:09

dot


1 Answers

Use xs:enumeration:

<xs:element name="TYPE">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
      <xs:enumeration value="Index"/>
      <xs:enumeration value="Condition"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>
like image 112
kjhughes Avatar answered Sep 17 '25 09:09

kjhughes