<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">

<!--Here is the definition for the base type. Note that the attribute declaration must go outside of the sequence, not inside it as erroneously shown in Figure 7.29.-->
<xsd:complexType name="characteristicsType">
	<xsd:sequence>
		<xsd:element name="weight" type="xsd:string"/>
		<xsd:element name="length" type="xsd:string"/>
	</xsd:sequence>
	<xsd:attribute name="kind" type="xsd:string"/>
</xsd:complexType>

<!--Here is the definition of the new type which is based on the characteristicsType type shown above. This type, since it uses extension, will have to satisfy the criteria in characteristicsType as well as the new criteria specified here (that it include mother and birthdate elements).-->
<xsd:complexType name="birthType">
	<xsd:complexContent>
		<xsd:extension base="characteristicsType">
			<xsd:sequence>
				<xsd:element name="mother" type="xsd:string"/>
				<xsd:element name="birthdate" type="xsd:date"/>
			</xsd:sequence>
		</xsd:extension>
	</xsd:complexContent>
</xsd:complexType>

<xsd:element name="endangered_species" type="endspeciesType"/>
	
<xsd:complexType name="endspeciesType">
	<xsd:sequence>
		<xsd:element name="animal">
			<xsd:complexType>
				<xsd:sequence>
					<xsd:element ref="name"/>
					<xsd:element name="characteristics" type="characteristicsType"/>
					<xsd:element name="subspecies" type="subspeciesType"/>
				</xsd:sequence>
			</xsd:complexType>
		</xsd:element>
		
		<xsd:element name="individual">
			<xsd:complexType>
				<xsd:sequence>
				<!--Here is where we reference the new derived complex type and use it to define the birth_characteristics element. -->
				<xsd:element name="birth_characteristics" type="birthType"/>
				</xsd:sequence>
				<xsd:attribute name="nickname" type="xsd:string"/>
			</xsd:complexType>
		</xsd:element>
	</xsd:sequence>
</xsd:complexType>

<xsd:element name="name">
	<xsd:complexType>
	<xsd:simpleContent>
		<xsd:extension base="xsd:string">
			<xsd:attribute name="language" type="languageType"/>
		</xsd:extension>
	</xsd:simpleContent>
	</xsd:complexType>
</xsd:element>

<xsd:simpleType name="languageType">
	<xsd:restriction base="xsd:string">
		<xsd:enumeration value="English"/>
		<xsd:enumeration value="Latin"/>
	</xsd:restriction>
</xsd:simpleType>


<xsd:complexType name="subspeciesType">
	<xsd:sequence>
		<xsd:element ref="name" minOccurs="1" maxOccurs="unbounded"/>
		<xsd:element name="region" type="xsd:string"/>
		<xsd:element name="population">
			<xsd:complexType>
				<xsd:simpleContent>
					<xsd:extension base="xsd:nonNegativeInteger">
						<xsd:attribute name="year" type="xsd:year"/>
					</xsd:extension>
				</xsd:simpleContent>
			</xsd:complexType>
		</xsd:element>
	</xsd:sequence>	
</xsd:complexType>
		
</xsd:schema>

		


		
