<?xml version="1.0" encoding="UTF-8" ?>
<!--
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
		targetNamespace="http://www.vehicle.org"
		xmlns:v="http://www.vehicle.org"
		elementFormDefault="qualified">
		
	<element name="vehicle">
		<complexType>
			<attribute name="plateNumber" type="integer"/>
			<attribute name="state" type="string"/>
		</complexType>
	</element>

	<element name="state">
		<complexType>
			<sequence>
				<element name="code" type="string" maxOccurs="unbounded"/>
				<element ref="v:vehicle" maxOccurs="unbounded" minOccurs="0"/>
				<element ref="v:person" maxOccurs="unbounded" minOccurs="0"/>
			</sequence>
		</complexType>
		
		<key name="reg"> <!-- vehicles are keyed by their plate within states -->
			<selector xpath=".//v:vehicle"/>
			<field xpath="@plateNumber"/>
		</key>
	</element>

	<element name="root">
		<complexType>
			<sequence>
				<element ref="v:state" maxOccurs="unbounded"/>
			</sequence>
		</complexType>
		
		<key name="state"> <!-- states are keyed by their code -->
			<selector xpath=".//v:state"/>
			<field xpath="v:code"/>
		</key>
		
		<keyref name="vehicleState" refer="v:state">
			<!-- every vehicle refers to its state -->
			<selector xpath=".//v:vehicle"/>
			<field xpath="@state"/>
		</keyref>
		
		<key name="regKey"> <!-- vehicles are keyed by a pair of state and plate -->
			<selector xpath=".//v:vehicle"/>
			<field xpath="@state"/>
			<field xpath="@plateNumber"/>
		</key>
		
		<keyref name="carRef" refer="v:regKey"> <!-- people's cars are a reference -->
			<selector xpath=".//v:car"/>
			<field xpath="@regState"/>
			<field xpath="@regPlate"/>
		</keyref>
	</element>

	<element name="person">
		<complexType>
			<sequence>
				<element name="car" maxOccurs="unbounded">
					<complexType>
						<attribute name="regState" type="string"/>
						<attribute name="regPlate" type="integer"/>
					</complexType>
				</element>
			</sequence>
		</complexType>
	</element>
</schema>
