XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Best practice for XSD enumeration values?

Hi Kurt,

On Thu, Feb 17, 2022 at 11:09 AM Kurt Cagle <kurt.cagle@gmail.com> wrote:
If you had to do this as an enumeration, I'd use the following:
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="airportType">
        <xsd:simpleType>
            <xsd:list>
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:enumeration value="civil"/>
                        <xsd:enumeration value="military"/>
                        <xsd:enumeration value="active"/>
                        <xsd:enumeration value="inactive"/>
                        <xsd:enumeration value="permanent"/>
                        <xsd:enumeration value="temporary"/>
                    </xsd:restriction>                  
                </xsd:simpleType>               
            </xsd:list>
        </xsd:simpleType>
    </xsd:element>
</xsd:schema>
Then you would have:
<airportType>active civil permanent</airportType>

 Nice thought.

The schema you've posted, would allow the XML element <airportType>active active civil permanent</airportType> to be reported as valid (i.e, duplicate strings are permitted).

It seems that, a modification like following (with XSD 1.1 needed) could fix that,

<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   
    <xsd:element name="airportType">
        <xsd:simpleType>
           <xsd:restriction base="AirportType">
              <xsd:assertion test="count($value) = count(distinct-values($value))"/>
           </xsd:restriction>
        </xsd:simpleType>
    </xsd:element>
   
    <xsd:simpleType name="AirportType">
       <xsd:list>
          <xsd:simpleType>
             <xsd:restriction base="xsd:string">
               <xsd:enumeration value="civil"/>
               <xsd:enumeration value="military"/>
               <xsd:enumeration value="active"/>
               <xsd:enumeration value="inactive"/>
               <xsd:enumeration value="permanent"/>
               <xsd:enumeration value="temporary"/>
             </xsd:restriction>                  
          </xsd:simpleType>              
       </xsd:list>
    </xsd:simpleType>
   
</xsd:schema>


--
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS