Home > Mobile >  XSD restriction: is it possible to define a pattern based on an enumeration?
XSD restriction: is it possible to define a pattern based on an enumeration?

Time:11-03

I'd like to restrict a field so that it can only begins with some specific values. This is what I tried:

<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:pattern value="(green apple) |(blue orange) |(lemon 123) "/>
  </xs:restriction>
</xs:simpleType>

and also

<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:pattern value="(green apple|blue orange|lemon 123) "/>
  </xs:restriction>
</xs:simpleType>

Doing so, I was hopping that
green apple: valid
green apple (Gala): valid
red apple: not valid

But none of these attempts were successful. Any idea how I could achieve that?

EDIT: I changed so enum values, so that they now contain whitespace

CodePudding user response:

You want

<xs:pattern value="(apple|orange|lemon). "/>

CodePudding user response:

Define each phrase as their own pattern.

          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:pattern value="green apple. " />
              <xs:pattern value="blue orange. " />
              <xs:pattern value="lemon 123. " />
            </xs:restriction>
          </xs:simpleType>
  • Related