简体   繁体   中英

How relax enum in xsd for value outside enum

Sorry if this is a stupid question but have to ask to know if this is possible So this is XSD

<xs:simpleType name="PhoneTypeEnum">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Fax"/>
        <xs:enumeration value="Voice"/>
        <xs:enumeration value="Pager"/>
    </xs:restriction>
</xs:simpleType>

The relaxation is below

  1. When we get values where fax or FAX the validation should not fail and still except as Fax as correct value.
  2. When there is no values matching either of Fax,Voice or Pager then also XSD validation should not fail but go as unknown as values.

Is this possible in XSD schema validation? If not then we have to do this in custom code validation in java.

Please suggest if this is doable?

With XSD 1.0 the only way to do case-blind matching is along the lines

<xs:restriction base="xs:string">
  <xs:pattern value="[Ff][Aa][Xx]|[Vv][Oo][Ii][Cc][Ee]|..."/>
</xs:restriction>

With XSD 1.1 you could use an assertion instead.

But I don't understand your requirement that validation shouldn't fail if the conditions aren't met. (Technically, validation never fails: it reports an element as being either valid or invalid. However, most schema processors don't make it easy to validate a document and then inspect the nodes to see which are valid and which aren't.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM