Nested List Datatypes - Not Allowed

This section provides a tutorial example on how list datatypes and list union datatypes are now allowed as item datatypes to construct nested list datatypes.

Can we construct a list datatype using another list datatype as the item datatype to build a "two-dimensional" list? The answer is now. I think the reason is that the "list" component does not allow you specify your own item delimiter. If the outer list and the inner list both use the default whitespace as delimiters, there is no way to know to know where is the end of the first item of the outer list.

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

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

<xs:simpleType name="list">
  <xs:list itemType="xs:date"/>
</xs:simpleType>

<xs:simpleType name="listUnion">
  <xs:union memberTypes="xs:gYear">
    <xs:simpleType>
      <xs:list itemType="xs:unsignedByte"/>
    </xs:simpleType>
  </xs:union>
</xs:simpleType>

<xs:element name="Nest_List_Test">
  <xs:complexType>
    <xs:sequence>

      <xs:element name="ListOfList" maxOccurs="unbounded">
        <xs:simpleType>
          <xs:list itemType="list"/>
        </xs:simpleType>
      </xs:element>

      <xs:element name="ListOfListUnion" maxOccurs="unbounded">
        <xs:simpleType>
          <xs:list itemType="listUnion"/>
        </xs:simpleType>
      </xs:element>

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

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

herong> java XsdSchemaChecker nested_list_test_invalid.xsd

Error:
   Line number: 25
   Column number: 37
   Message: cos-st-restricts.2.1: In the definition of list type
   '#AnonType_ListOfListNest_List_Test', type 'list' is an invalid
   item type because it is either a list type, or a union type that
   contains a list.

Error:
   Line number: 31
   Column number: 42
   Message: cos-st-restricts.2.1: In the definition of list type
   '#AnonType_ListOfListUnionNest_List_Test', type 'listUnion' is an
   invalid item type because it is either a list type, or a union
   type that contains a list.

Schema File: nested_list_test_invalid.xsd
Parser Class: com.sun.org.apache.xerces.internal.jaxp.validation
   .SimpleXMLSchema

Failed with 2 errors.

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