0

XML enum element (with max occurs > 1) is accepting

"Status": [
     null
 ]

which I do not want. I only want to accept valid strings defined in the enum.

Have tried setting the restriction of the enum to minimum length of 1 which did not seem to solve the issue

<simpleType name="statusType">
        <restriction base="string" >

          <enumeration value="UNDER_VERIFICATION"></enumeration>
          <enumeration value="STOPPED"></enumeration>
        </restriction>
</simpletype>

usage:

 <element name="status" type="common:statusType"
                maxOccurs="unbounded" minOccurs="0">

</element>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
bgore
  • 98
  • 1
  • 11
  • I just re-read your question and see that your problem remained after setting `minOccurs="1"`. See my answer confirming what your XSD and such a variation means at the XML level. If your problem persists at the code level, state the language and post the problematic code for more specific help. See [mcve]. Thanks. – kjhughes Aug 21 '19 at 12:16

1 Answers1

0

Your status element as defined will only be valid with either of the following values:

<status>UNDER_VERIFICATION</status>
<status>STOPPED</status>

While it will not be valid with no content,

<status></status>

the status element itself is currently not required because of minOccurs="0". Change that to minOccurs="1" to make the status element itself be required:

<element name="status" type="common:statusType"
         maxOccurs="unbounded" minOccurs="1"/>

You may also omit minOccurs as its default value is 1. See XML Schema minOccurs / maxOccurs default values for further details.

kjhughes
  • 106,133
  • 27
  • 181
  • 240