Nonatomic Types

Contact Us or call 1-877-932-8228
Nonatomic Types

Nonatomic Types

All of XML Schema's built-in types are atomic, meaning that they cannot be broken down into meaningful bits. XML Schema provides for two nonatomic types: lists and unions.

Lists

List types are sequences of atomic types separated by whitespace; you can have a list of integers or a list of dates. Lists should not be confused with enumerations. Enumerations provide optional values for an element. Lists represent one or more values within an element.

Code Sample:

SimpleTypes/Demos/EmployeeList.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:simpleType name="Salary">
		<xs:restriction base="xs:decimal">
			<xs:minInclusive value="10000"/>
			<xs:maxInclusive value="90000"/>
			<xs:fractionDigits value="2"/>
			<xs:totalDigits value="7"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="JobTitle">
		<xs:restriction base="xs:string">
			<xs:enumeration value="Sales Manager"/>
			<xs:enumeration value="Salesperson"/>
			<xs:enumeration value="Receptionist"/>
			<xs:enumeration value="Developer"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="DateList">
		<xs:list itemType="xs:date"/>
	</xs:simpleType>
	<xs:element name="Employee">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Salary" type="Salary"/>
				<xs:element name="Title" type="JobTitle"/>
				<xs:element name="VacationDays" type="DateList"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

Code Sample:

SimpleTypes/Demos/SandySmith.xml
<?xml version="1.0"?>
<Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:noNamespaceSchemaLocation="EmployeeList.xsd">
	<Salary>44000</Salary>
	<Title>Salesperson</Title>
	<VacationDays>2006-08-13 2006-08-14 2006-08-15</VacationDays>
</Employee>

Unions

Union types are groupings of types, essentially allowing for the value of an element to be of more than one type. In the example below, two atomic simple types are derived: RunningRace and Gymnastics. A third simple type, Event, is then derived as a union of the previous two. The Event element is of the Event type, which means that it can either be of the RunningRace or the Gymnastics type.

Code Sample:

SimpleTypes/Demos/Program.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:simpleType name="RunningRace">
		<xs:restriction base="xs:string">
			<xs:enumeration value="100 meters"/>
			<xs:enumeration value="10 kilometers"/>
			<xs:enumeration value="440 yards"/>
			<xs:enumeration value="10 miles"/>
			<xs:enumeration value="Marathon"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="Gymnastics">
		<xs:restriction base="xs:string">
			<xs:enumeration value="Vault"/>
			<xs:enumeration value="Floor"/>
			<xs:enumeration value="Rings"/>
			<xs:enumeration value="Beam"/>
			<xs:enumeration value="Uneven Bars"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="Event">
		<xs:union memberTypes="RunningRace Gymnastics"/>
	</xs:simpleType>
	<xs:element name="Program">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Event" type="Event"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

Code Sample:

SimpleTypes/Demos/100Meters.xml
<?xml version="1.0"?>
<Program xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:noNamespaceSchemaLocation="Program.xsd">
	<Event>100 meters</Event>
</Program>
Next