Reputation: 125
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
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 0
s if necessary.
Upvotes: 1