<?xml version="1.0" encoding="utf-8" ?>
<xs:schema 
	targetNamespace="http://www.microsoft.com/SqlServer/Dts/DataTypeMapping.xsd" 
	elementFormDefault="qualified"
	xmlns="http://www.microsoft.com/SqlServer/Dts/DataTypeMapping.xsd" 
	xmlns:xs="http://www.w3.org/2001/XMLSchema">
	
	<xs:element name="DataTypeMappings">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="DataTypeMapping" minOccurs="1" maxOccurs="unbounded" type="DataTypeMappingType" />
			</xs:sequence>
			<xs:attributeGroup ref="SourceDestinationInfo" />
		</xs:complexType>
	</xs:element>
	
	<xs:complexType name="DataTypeMappingType">
		<xs:sequence>
			<xs:element name="SourceDataType" type="SimpleTypeSpecification"></xs:element>
			<xs:element name="DestinationDataType" type="DestinationDataTypeSpecification"></xs:element>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="DestinationDataTypeSpecification">
		<xs:choice>
			<xs:element name="SimpleType" type="SimpleTypeSpecification" />
			<!-- only data type name -->
			<xs:element name="CharacterStringType" type="CharacterStringTypeSpecification" />
			<!-- data type with collation/character set/etc. -->
			<xs:element name="BitStringType" type="DataTypeWithLengthSpecification" />
			<!-- data type with length -->
			<xs:element name="NumericType" type="NumericTypeSpecification" />
			<!-- data type with precision and scale -->
		</xs:choice>
	</xs:complexType>
	
	<xs:group name="DataTypeNameGroup">
		<xs:sequence>
			<xs:element name="DataTypeName" maxOccurs="1" type="xs:normalizedString"/>
		</xs:sequence>
	</xs:group>
	
	<xs:complexType name="SimpleTypeSpecification">
		<xs:group ref="DataTypeNameGroup" minOccurs="1" maxOccurs="1" />
	</xs:complexType>
	
	<xs:complexType name="CharacterStringTypeSpecification">
		<!--
			Data type can be specified as one of: 
			 Use destination provider default - skip explicit setting
			 Use source setting - get the length from the source
			 Length - set to an explicit length specified in the file
		-->
		<xs:sequence>
			<xs:group ref="DataTypeNameGroup" minOccurs="1" maxOccurs="1" />
			<xs:choice>
				<xs:element name="Length" maxOccurs="1" type="xs:int"/>
				<xs:element name="SkipLength" maxOccurs="1">
					<!-- empty element -->
					<xs:complexType />
				</xs:element>
				<xs:element name="UseSourceLength" maxOccurs="1">
					<!-- empty element -->
					<xs:complexType />
				</xs:element>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="DataTypeWithLengthSpecification">
		<xs:sequence>
			<xs:group ref="DataTypeNameGroup" minOccurs="1" maxOccurs="1" />
				<xs:element name="Length" maxOccurs="1" type="xs:int"/>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="NumericTypeSpecification">
		<xs:sequence>
			<xs:group ref="DataTypeNameGroup" minOccurs="1" maxOccurs="1"/>
			<xs:choice>
				<xs:element name="Precision" type="xs:unsignedInt" maxOccurs="1" />
				<xs:element name="UseSourcePrecision" maxOccurs="1">
					<!-- empty -->
					<xs:complexType/>
				</xs:element>
				<xs:element name="SkipPrecision" maxOccurs="1">
					<!-- empty -->
					<xs:complexType/>
				</xs:element>
			</xs:choice>
			<xs:choice>
				<xs:element name="Scale" type="xs:unsignedInt" maxOccurs="1" />
				<xs:element name="UseSourceScale" maxOccurs="1">
					<!-- empty -->
					<xs:complexType/>
				</xs:element>
				<xs:element name="SkipScale" maxOccurs="1">
					<!-- empty -->
					<xs:complexType/>
				</xs:element>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>
	
	<xs:attributeGroup name="SourceDestinationInfo">
		<xs:attribute name="SourceType" type="xs:string" use="required" />
		<xs:attribute name="MinSourceVersion" type="xs:string" default="*" />
		<xs:attribute name="MaxSourceVersion" type="xs:string" default="*" />
		<xs:attribute name="DestinationType" type="xs:string" use="required" />
		<xs:attribute name="MinDestinationVersion" type="xs:string" default="*" />
		<xs:attribute name="MaxDestinationVersion" type="xs:string" default="*" />
	</xs:attributeGroup>
	
</xs:schema>