Prabhu Sethupathy
Prabhu Sethupathy

Reputation: 125

XSD Alternative for union

I'm working on a xsd and my system poses restriction on the usage of the element <union>. Below is the code snippet:

<xsd: element name = 'CRN' minOccurs = "1">
  <xsd: simpleType>
   <xsd:union memberTypes = "fps:nonNegativeMax999IntType fps:FullPaymentSubmission_XType"/>
  /xsd:simpleType>

<xsd:simpleType name = "FullPaymentSubmission_XType">
  <xsd:restriction base="xsd:string">
   <xsd:enumeration value = "X"/>
  </xsd:restriction> 
</xsd:simpleType>

<xsd:simpleType name = "nonNegativeMax999IntType ">
  <xsd:restriction base="xsd:nonNegativeInteger">
   <xsd:maxInclusive value = "9999"/>
  </xsd:restriction> 
</xsd:simpleType>

Please can someone suggest an alternative for this where I can avoid using <union> in my xsd ?

Upvotes: 1

Views: 736

Answers (1)

kjhughes
kjhughes

Reputation: 111621

This XSD,

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="r">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:pattern value="\d{1,4}"/>
        <xs:pattern value="X"/>
        <xs:pattern value="Y"/>
        <xs:pattern value="Z"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>

will allow CRN to be up to 4 digits or X or Y or Z. You can adjust the regex for any other requirements such as an optional leading + or excluding leading 0s if necessary.

Upvotes: 1

Related Questions