Soph
Soph

Reputation: 2915

How to create an XSD type which accepts a series of predefined values?

I am trying to define a type to use in my XML document where it only accepts for that specific datatype, one of the following values:

Is this possible?

Upvotes: 0

Views: 52

Answers (1)

Soph
Soph

Reputation: 2915

Ok, I just found the answer using the attribute "enumeration". Here is the explanation, and the following code is the example used in it:

<xs:element name="car">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:enumeration value="Audi"/>
      <xs:enumeration value="Golf"/>
      <xs:enumeration value="BMW"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

Upvotes: 1

Related Questions