"simpleType" Components with "list" Child Components

This section describes the 'list' child component in 'simpleType' component. 'list' child components are used to create a new value space of lists with member values from another simple datatype.

"list" child component in a "simpleType" component offers a third way of defining a new simple datatype by create a new value space of lists with member values from another simple datatype.

Here is an XSD template showing you how to use the "list" as a child component in a "simpleType" component:

Format 1:
<simpleType ...>
  <list itemType="item_type">
</simpleType>

Format 2:
<simpleType ...>
  <list>
    <simpleType ...>
      definition of item datatype
    </simpleType>
  </union>
</simpleType>

Some notes on using the "list" component:

For example, the following XSD document uses "list" components to define 2 new simple datatypes:

<?xml version="1.1"?>
<!-- list_simpleType_test.xsd
 - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="List_SimpleType_Test">
  <xs:complexType>
    <xs:sequence>

      <xs:element name="Winners" maxOccurs="unbounded">
        <!-- "list" with "itemType" attribute -->
        <xs:simpleType>
          <xs:list itemType="xs:NCName"/>
        </xs:simpleType>
      </xs:element>

      <xs:element name="WinningNumbers" maxOccurs="unbounded">
        <!-- "list" with no "itemType" attribute -->
        <xs:simpleType>
          <xs:list>
            <xs:simpleType>
              <xs:restriction base="xs:unsignedByte">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="49"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:list>
        </xs:simpleType>
      </xs:element>

    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

Here is a sample XML document to test the above XSD document:

<?xml version="1.1"?>
<!-- list_simpleType_test.xml
 - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved.
-->
<List_SimpleType_Test>

   <!-- Valid "Winners" list values -->
   <Winners>  Herong Mike Bill  </Winners>

   <!-- Invalid "Winners" values -->
   <Winners>  "Herong Yang" </Winners>

   <!-- Valid "WinningNumbers" list values -->
   <WinningNumbers>  1 20 24 33    37     43  </WinningNumbers>

   <!-- Invalid "WinningNumbers" values -->
   <WinningNumbers>  888  </WinningNumbers>
   <WinningNumbers>  1,20,24,33,37,43  </WinningNumbers>
</List_SimpleType_Test>

When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book, I get these errors:

herong> java XsdSchemaValidator
^^^ list_simpleType_test.xsd list_simpleType_test.xml

Error:
   Line number: 11
   Column number: 39
   Message: cvc-datatype-valid.1.2.1: '"Herong' is not a valid value
   for 'NCName'.

Error:
   Line number: 11
   Column number: 39
   Message: cvc-type.3.1.3: The value '"Herong Yang"' of element
   'Winners' is not valid.

Error:
   Line number: 17
   Column number: 44
   Message: cvc-maxInclusive-valid: Value '888' is not facet-valid
   with respect to maxInclusive '49' for type
   '#AnonType_WinningNumbersList_SimpleType_Test'.

Error:
   Line number: 17
   Column number: 44
   Message: cvc-type.3.1.3: The value '888' of element
   'WinningNumbers' is not valid.

Error:
   Line number: 18
   Column number: 57
   Message: cvc-datatype-valid.1.2.1: '1,20,24,33,37,43' is not a
   valid value for 'integer'.

Error:
   Line number: 18
   Column number: 57
   Message: cvc-type.3.1.3: The value '1,20,24,33,37,43' of element
   'WinningNumbers' is not valid.

Failed with errors: 6

Table of Contents

 About This Book

 Introduction to XML Schema

 XML Editor and Schema Processor - XMLPad

 Java API for XML Processing - JAXP

 JAXP - XML Schema (XSD) Validation

 Xerces2 Java Parser - Java API of XML Parsers

 Using Xerces2 Java APIs

 XML Schema Language - Basics

 Introduction of XSD Built-in Datatypes

 "string" and Its Derived Datatypes

 "decimal" and Its Derived Datatypes

 "dateTime" and Its Related Datatypes

 Miscellaneous Built-in Datatypes

 Facets, Constraining Facets and Restriction Datatypes

"simpleType" - Defining Your Own Simple Datatypes

 What Is Simple Datatype?

 "simpleType" Components - User-Defined Simple Datatypes

 "simpleType" Components with "restriction" Child Components

 "simpleType" Components with "union" Child Components

"simpleType" Components with "list" Child Components

 Atomic, List, Atomic Union and List Union Datatypes

 Constraining Facets on List Datatypes

 Constraining Facets on Union Datatypes

 Nested List Datatypes - Not Allowed

 Nested Atomic and List Union Datatypes

 Complex Element Declaration

 Identity-Constraints: unique, key and keyref

 Assertion as Custom Validation Rules

 XML Schema Location and Namespace in XML Documents

 Overriding Element Types in XML Documents

 Linking Multiple Schema Documents Together

 Glossary

 Archived Tutorials

 References

 Full Version in PDF/EPUB