Link to home
Avatar of SusanLIMS
SusanLIMS

asked on

XSD - Element required, Matching Values, empty Allowed

I'm new to XSD and this is probably a simple question.  In the snippet below -
the element TOBACCO_USE.
The element is REQUIRED to be present, but the value may be empty.  If it is populated,
it must have a value of YES, NO or UNKNOWN.
I'm not sure how to specify this combination of requirements.
i.e. I think that "sequence" says the element must be present.
But when I specify a pattern value - how is it known that empty is allowed?  And what would be the difference if empty were not allowed?

Thanks much...Susan

<xs:element name="orders">
  <xs:complexType>
    <xs:sequence>
        <xs:element name="X_EXTERNAL_ID">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:length value="12"/>
                    <xs:pattern value="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="Z_BUSINESS_UNIT">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="ILS|CLS|TLS|WLS"/>                            
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="Z_CORPORATION">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="[A-Z_\-\.]{0,40}"/>                        
                </xs:restriction>
            </xs:simpleType>
        <xs:element name="Z_TOBACCO_USE">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="YES|NO|UNKNOWN"/>                            
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of SusanLIMS
SusanLIMS

ASKER

THANKS!!