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>
XML

Avatar of undefined
Last Comment
Gertone (Geert Bormans)

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SusanLIMS

ASKER
THANKS!!
Gertone (Geert Bormans)

welcome
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck