∟"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:
itemType="item_type" - Optional attribute to specify the item datatype
who's value will be used as list items.
If not provided, the item datatype must be defined with a child "simpleType" component.
The item datatype can not be a list datatype.
In other words, list datatypes can not be nested.
The lexical representation of a list value is a list item values separated by whitespaces.
For example, the following XSD document uses "list" components to define 2 new simple datatypes:
Here is a sample XML document to test the above XSD document:
<?xml version="1.1"?>
<!-- list_simpleType_test.xml
- Copyright (c) 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:
c:\Progra~1\Java\jdk1.7.0_07\bin\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