Blue Eden
Blue Eden

Reputation: 59

How to allow multiple different lengths for strings in XSD?

So I have a custom data type:

<xs:simpleType name="AbbreviatedTeamName">
    <xs:restriction base="xs:string">
        <xs:length value="3"/>
    </xs:restriction>
</xs:simpleType>

I would like to have either 3 or 0 to be valid in the

    <xs:length value="3"/>

such as:

    <xs:length value="3" or value="0"/>

But I am unsure of how to do this or if this is even possible.

Upvotes: 1

Views: 287

Answers (1)

kjhughes
kjhughes

Reputation: 111686

Usexs:pattern to specify a regular expression that restricts a string to be 0 or 3 characters long:

  <xs:simpleType name="AbbreviatedTeamName">
    <xs:restriction base="xs:string">
      <xs:pattern value="|..."/>
    </xs:restriction>
  </xs:simpleType>

Upvotes: 4

Related Questions