troubleshooting Question

XSD - Element required, Matching Values, empty Allowed

Avatar of SusanLIMS
SusanLIMS asked on
XML
3 Comments1 Solution434 ViewsLast Modified:
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
Gertone (Geert Bormans)
Information Architect
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros