[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Examples of all the different ways of creating XML SchemasimpleTypes

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Fri, 24 Jun 2011 13:53:18 -0400

Examples of all the different ways of creating XML SchemasimpleTypes
Hi Folks,

Below is an XML Schema. It contains examples of all the different ways of creating simpleTypes. Please let me know if there are other ways that I haven't accounted for.  /Roger


<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                     targetNamespace="http://www.example.org"
                     xmlns="http://www.example.org"
                     elementFormDefault="qualified">
        
    <!-- 
        Lists
        1. An unbounded list of integers
        2. A list of integers, constrained to 10 items in the list
        3. A restriction of a type that is a list of integers, constrained to 5 items of the type
        4. A list of strings that are constrained by a regex and a maxLength of 15, and the list is constrained to 4 items
    -->
    
    <!-- ******************************** -->
    <!-- 1. An unbounded list of integers -->
    <!-- ******************************** -->
    
    <xsd:element name="Numbers" type="Numbers" />
    
    <xsd:simpleType name="Numbers">
        <xsd:list itemType="xsd:integer" />
    </xsd:simpleType>
    
    <!-- ********************************************************** -->
    <!-- 2. A list of integers, constrained to 10 items in the list -->
    <!-- ********************************************************** -->
    
    <xsd:element name="Ten-Numbers" type="Ten-Numbers" />
    
    <xsd:simpleType name="Ten-Numbers">
        <xsd:restriction>
            <xsd:simpleType>
                <xsd:list itemType="xsd:integer" />
            </xsd:simpleType>
            <xsd:length value="10"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <!-- ***************************************************************************************** -->
    <!-- 3. A restriction of a type that is a list of integers, constrained to 5 items of the type -->
    <!-- ***************************************************************************************** -->
    
    <xsd:element name="Five-Numbers" type="Five-Numbers" />
    
    <xsd:simpleType name="Five-Numbers">
        <xsd:restriction base="Numbers">
            <xsd:length value="5"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <!-- ****************************************************************************************************************** -->
    <!-- 4. A list of strings that are constrained by a regex and a maxLength of 15, and the list is constrained to 4 items -->
    <!-- ****************************************************************************************************************** -->

    <xsd:element name="Names" type="Names" />
    
    <xsd:simpleType name="Names">
        <xsd:restriction>
            <xsd:simpleType>
                <xsd:list itemType="Name"/>
            </xsd:simpleType>
            <xsd:length value="4"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <xsd:simpleType name="Name">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="15" />
            <xsd:pattern value="[a-zA-Z]*" />
        </xsd:restriction>
    </xsd:simpleType>
    
    <!-- *********************************************** -->
    <!-- 5. Same as (4), except the list type is inlined -->
    <!-- *********************************************** -->
    
    <xsd:element name="Names-Inlined" type="Names-Inlined" />
    
    <xsd:simpleType name="Names-Inlined">
        <xsd:restriction>
            <xsd:simpleType>
                <xsd:list>
                    <xsd:simpleType >
                        <xsd:restriction base="xsd:string">
                            <xsd:maxLength value="15" />
                            <xsd:pattern value="[a-zA-Z]*" />
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:list>
            </xsd:simpleType>
            <xsd:length value="4"/>
        </xsd:restriction>
    </xsd:simpleType>
    

    
    <!-- 
        Unions
        6. A union of string and integer
        7. A union of a nonNegativeInteger and a single string
        8. A union of a strings of maxLength 10 and integers of maxInclusive 50
        9. A simpleType that is a synonym for the Names-and-Numbers simpleType
    -->
    
    <!-- ******************************** -->
    <!-- 6. A union of string and integer -->
    <!-- ******************************** -->

    <xsd:element name="Names-and-Numbers" type="Names-and-Numbers" />
    
    <xsd:simpleType name="Names-and-Numbers">
        <xsd:union memberTypes="xsd:string xsd:integer" />
    </xsd:simpleType>
    
    <!-- ****************************************************** -->
    <!-- 7. A union of a nonNegativeInteger and a single string -->
    <!-- ****************************************************** -->
    
    <xsd:element name="maxOccurs" type="maxOccurs" />
    
    <xsd:simpleType name="maxOccurs">
        <xsd:union memberTypes="xsd:nonNegativeInteger" >
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="unbounded" />
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:union>
    </xsd:simpleType>
 
    <!-- *********************************************************************** -->
    <!-- 8. A union of a strings of maxLength 10 and integers of maxInclusive 50 -->
    <!-- *********************************************************************** -->
    
    <xsd:element name="Restricted-Names-and-Numbers" type="Restricted-Names-and-Numbers" />
    
    <xsd:simpleType name="Restricted-Names-and-Numbers">
        <xsd:union>
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:maxLength value="10" />
                </xsd:restriction>
            </xsd:simpleType>
            <xsd:simpleType>
                <xsd:restriction base="xsd:integer">
                    <xsd:maxInclusive value="50" />
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:union>
    </xsd:simpleType>

    <!-- ********************************************************************** -->
    <!-- 9. A simpleType that is a synonym for the Names-and-Numbers simpleType -->
    <!-- ********************************************************************** -->
    
    <xsd:element name="My-Names-and-Numbers" type="My-Names-and-Numbers" />
    
    <xsd:simpleType name="My-Names-and-Numbers">
        <xsd:restriction base="Names-and-Numbers" />
    </xsd:simpleType>
    
    <!-- 
        Other
        10. A simpleType restricts a simpleType which restricts another simpleType
        11. Same as (10) except all simpleTypes are inlined
    -->
    
    <!-- ************************************************************************** -->
    <!-- 10. A simpleType restricts a simpleType which restricts another simpleType -->
    <!-- ************************************************************************** -->
    
    <xsd:simpleType name="BostonAreaSurfaceElevation">
        <xsd:restriction base="EarthSurfaceElevation">
            <xsd:minInclusive value="0"/>
            <xsd:maxInclusive value="120"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <xsd:simpleType name="EarthSurfaceElevation">
        <xsd:restriction base="Elevation">
            <xsd:minInclusive value="-1290"/>
            <xsd:maxInclusive value="29035"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <xsd:simpleType name="Elevation">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="-999999"/>
            <xsd:maxInclusive value="999999"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <!-- *************************************************** -->
    <!-- 11. Same as (10) except all simpleTypes are inlined -->
    <!-- *************************************************** -->
    
    <xsd:simpleType name="BostonAreaSurfaceElevation-Inlined">
        <xsd:restriction>
            <xsd:simpleType>
                <xsd:restriction>
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:integer">
                            <xsd:minInclusive value="-999999"/>
                            <xsd:maxInclusive value="999999"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                    <xsd:minInclusive value="-1290"/>
                    <xsd:maxInclusive value="29035"/>
                </xsd:restriction>
            </xsd:simpleType>
            <xsd:minInclusive value="0"/>
            <xsd:maxInclusive value="120"/>
        </xsd:restriction>
    </xsd:simpleType>
    
</xsd:schema>


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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.