<?xml version="1.0" encoding="UTF-8"?>
<!--
	Central Council of Church Bell Ringers, Methods Committee
	
	XML Schema for method definitions and method collections
	Version 1.0 specification
	http://www.cccbr.org.uk/methods/schemas/2007/05/methods
	
	Copyright (c) 2005, 2007
	
	This schema contains three global element definitions that are intended for use as document roots:
	
	1. The <method> global element. This contains data concerning a single method
	2. The <methodSet> global element. This is intended to contain a group of methods which have some properties in common
	3. The <collection> global element which can be used in a document that contains a whole collection of methods, possibly with
	quite different properties. The <collection> element contains 0 or more <methodSet> elements
	
	In addition it contains the complex types used by these three elements:
	
	4. The complex type definition called methodType, which is the type used by <method>.
	5. The complex type definition called methodSetType, which is the type used by <methodSet>.
	6. The complex type definition called collectionType, which is the type used by <collection>.
	
	It also defines two substitution groups:
	
	7. A substitution group for references, with an abstract head and some concrete instantiations.
	8. A substitution group for performance references, with an abstract head and some concrete instantiations.
	
	The methodSetType and methodType definitions are fairly open-ended - most of their contents are optional. This is to allow them to be used in a variety of different contexts.
	
	Users can adapt these definitions as follows:
	
	- Omit optional contents
	- Add references or performance references from their own namespaces to the method element, using the substitution groups.
	- Add additional elements from their own namespaces as children of the notes and meta elements.
	- Add attributes from their own namespaces to the collection, methodSet or method elements.
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
	xmlns:mx="http://www.cccbr.org.uk/methods/schemas/2007/05/methods"
	targetNamespace="http://www.cccbr.org.uk/methods/schemas/2007/05/methods" elementFormDefault="qualified">
	<annotation>
		<documentation>
		Central Council of Church Bell Ringers, Methods Committee.

		XML Schema for method definitions and method collections. Version 1.0  specification.

		This schema defines the format used by Central Council XML methods collections, and also provides a global
		element definition called method which can be used to pass XML-formatted method definition and metadata
		between ringing programs.

		</documentation>
	</annotation>

	<import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd" />

	<!--  The Global Element Definitions    -->

	<element name="method" type="mx:methodType" />
	<element name="methodSet" type="mx:methodSetType" />
	<element name="collection" type="mx:collectionType" />

	<!--  The types used by these Global Element Definitions    -->

	<complexType name="collectionType">
		<sequence>
			<element name="collectionName" type="token" minOccurs="0"/>
			<element ref="mx:notes" minOccurs="0">
				<annotation>
					<documentation>
						An human-language description of the collection, along with any relevant comments to assist in
						its interpretation.
					</documentation>
				</annotation>

			</element>
			<element ref="mx:methodSet" maxOccurs="unbounded" />
		</sequence>
		<attribute name="uuid" type="anyURI">
			<annotation>
				<documentation>An id that uniquely identifies this collection and its revision level.</documentation>
			</annotation>
		</attribute>
		<attribute name="date" type="date"/>
		<attribute ref="mx:decisionsYear" />
		<anyAttribute namespace="##other" processContents="lax" />

	</complexType>

	<!--  The type used by the methodSet Global Element Definition   -->
	<complexType name="methodSetType">
		<annotation>
			<documentation>
				This type contains a list of methods, and can contain a set of properties. These properties apply to all
				the methods in the list, unless the method itself specifies a conflicting property value. If this
				happens then the value in the method definition takes precedence.
			</documentation>
		</annotation>

		<sequence>
			<element ref="mx:notes" minOccurs="0"/>
			<element name="properties">
				<complexType>
					<all>
						<element ref="mx:classification" minOccurs="0" />
						<element ref="mx:stage" minOccurs="0" />
						<element ref="mx:lengthOfLead" minOccurs="0" />
						<element ref="mx:numberOfHunts" minOccurs="0" />
						<element ref="mx:huntbellPath" minOccurs="0" />
						<element ref="mx:leadHead" minOccurs="0" />
						<element ref="mx:leadHeadCode" minOccurs="0" />
						<element ref="mx:falseness" minOccurs="0" />
						<element ref="mx:symmetry" minOccurs="0" />
						<element ref="mx:extensionConstruction" minOccurs="0" />
						<element ref="mx:notes" minOccurs="0" />
						<element ref="mx:meta" minOccurs="0" />
					</all>
				</complexType>
			</element>
			<element ref="mx:method" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
		<attribute ref="mx:decisionsYear" />
		<anyAttribute namespace="##other" processContents="lax" />
	</complexType>


	<!--    Global definitions shared by more than one type    -->

	<element name="classification">
		<complexType>
			<simpleContent>
				<extension base="mx:classType">
					<attribute name="little" type="boolean" default="false"></attribute>
					<attribute name="differential" type="boolean" default="false"></attribute>
					<attribute name="plain" type="boolean" default="false"></attribute>
					<attribute name="trebleDodging" type="boolean" default="false"></attribute>
				</extension>
			</simpleContent>
		</complexType>
	</element>

	<simpleType name="classType">
		<restriction base="string">
		    <enumeration value="" />
			<enumeration value="Place" />
			<enumeration value="Bob" />
			<enumeration value="Slow Course" />
			<enumeration value="Treble Bob" />
			<enumeration value="Delight" />
			<enumeration value="Surprise" />
			<enumeration value="Alliance" />
			<enumeration value="Treble Place" />
			<enumeration value="Hybrid" />
		</restriction>
	</simpleType>

	<element name="lengthOfLead" type="positiveInteger" />
	<element name="stage" type="positiveInteger" />
	<element name="numberOfHunts" type="nonNegativeInteger" />
	<element name="huntbellPath" type="mx:pathType">
		<annotation>
			<documentation>
				The path of the principal hunt bell, expressed using the positions visited by the bell.
			</documentation>
		</annotation>
	</element>

	<element name="leadHead" type="mx:rowType" />

	<element name="leadHeadCode" type="mx:leadHeadCodeType" />

	<element name="falseness">
		<complexType>
			<sequence>
				<element name="falseCourseHeads" minOccurs="0" maxOccurs="unbounded">
					<complexType>
						<all>
							<annotation>
								<documentation>
									In-course and out-of-course false course heads are listed separately. Note that
									these elements are optional, however the absence of one or other of these element
									does not imply that there are no such false course heads, it merely indicates that
									they are not recorded in the falseness element.
								</documentation>
							</annotation>
							<element name="inCourse" type="mx:fchType" minOccurs="0" />
							<element name="outOfCourse" type="mx:fchType" minOccurs="0" />
						</all>
						<attribute name="fixed" type="mx:fixedType" use="required"></attribute>
					</complexType>
				</element>
				<element name="fchGroups" type="mx:fchGroupType" minOccurs="0" />

			</sequence>
		</complexType>
	</element>

	<element name="notes">
		<complexType mixed="true">
			<sequence>
				<any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
			</sequence>
			<attribute ref="xml:lang"/>
		</complexType>
	</element>

	<element name="extensionConstruction">
		<simpleType>
			<restriction base="string">
				<pattern value="\d+([A-Z][A-Z])+/\d+([A-Z][A-Z])+"></pattern>
			</restriction>
		</simpleType>
	</element>
	
	<element name="symmetry">
		<simpleType>
			<list itemType="mx:symmetryType" />
		</simpleType>
	</element>

	<element name="meta">
		<complexType>
			<sequence>
				<any namespace="##other" processContents="lax" maxOccurs="unbounded" />
			</sequence>
		</complexType>
	</element>
		
	<element name="references">
		<complexType>
			<sequence>
				<element ref="mx:ref" minOccurs="1" maxOccurs="unbounded" />
			</sequence>
		</complexType>
	</element>

	<attribute name="decisionsYear" type="gYear">
		<annotation>
			<documentation>
				Classification and other data reflects the Central Council decisions current at the end of the meeting
				held in the year given by this attribute
			</documentation>
		</annotation>
	</attribute>

	<!--       Method definition type                            -->
	<complexType name="methodType">
		
		<all>

			<!--     Naming and Classification                 -->

			<element name="name" type="token" nillable="true" minOccurs="0">
				<annotation>
					<documentation>
						The name of the method. An empty name with the attribute xsi:nil="true" indicates that this
						method has not yet been officially named. Note that a blank name with xsi:nil="false" is valid
						in the case of Little Bob.
					</documentation>
				</annotation>
			</element>

			<element ref="mx:classification" minOccurs="0" />

			<element name="title" nillable="true" minOccurs="0">
				<simpleType>
					<restriction base="token">
						<minLength value="1" />
					</restriction>
				</simpleType>
			</element>

			<!--    Definitional elements                     -->

			<element ref="mx:stage" minOccurs="0" />

			<element name="notation" minOccurs="0" type="mx:notationType">
				<annotation>
					<documentation>Place notation for a lead of the method. Use - rather than x or X.</documentation>
				</annotation>
			</element>

			<!--    Technical metadata                        -->

			<element ref="mx:lengthOfLead" minOccurs="0" />

			<element ref="mx:leadHead" minOccurs="0" />
			
			<element ref="mx:numberOfHunts" minOccurs="0" />

			<element ref="mx:huntbellPath" minOccurs="0" />
			
			<element ref="mx:leadHeadCode" minOccurs="0" />

			<element ref="mx:falseness" minOccurs="0" />
				
		       <element ref="mx:symmetry" minOccurs="0" />

			<element ref="mx:extensionConstruction" minOccurs="0" />


			<!--      Other metadata                        -->

			<element ref="mx:notes" minOccurs="0" />

			<element ref="mx:meta" minOccurs="0" />

			<element ref="mx:references" minOccurs="0" />

			<element name="performances" minOccurs="0">
				<complexType>
					<sequence>
						<element ref="mx:performance" minOccurs="1" maxOccurs="unbounded" />
					</sequence>
				</complexType>
			</element>

		</all>
		<attribute name="id" type="ID" />
        <attribute ref="mx:decisionsYear" />
		<anyAttribute namespace="##other" processContents="lax" />
	</complexType>

	<!--          References defined by this schema             -->

	<element name="ref" type="mx:refType" abstract="true">
		<annotation>
			<documentation>
				This is the abstract definition of a reference to this method in some external source. This schema
				defines a number of concrete references. Users can define their own references in their own namespaces
				and adding them to the mx:ref substitution group
			</documentation>
		</annotation>
	</element>

	<element name="journalRef" substitutionGroup="mx:ref">
		<annotation>
			<documentation>References to this method in a journal.</documentation>
		</annotation>
		<complexType>
			<simpleContent>
				<restriction base="mx:journalRefType">
					<attribute name="journal" type="normalizedString" use="required" />
				</restriction>
			</simpleContent>
		</complexType>
	</element>

	<element name="rwRef" substitutionGroup="mx:ref">
		<annotation>
			<documentation>
				A list of one more references to this method in &quot;The Ringing World&quot;.
			</documentation>
		</annotation>
		<complexType>
			<simpleContent>
				<restriction base="mx:journalRefType">
					<pattern value="V?\d+/\d+(\s(V?\d+/)?\d+)*"></pattern>
					<attribute name="journal" type="normalizedString" fixed="The Ringing World" />
				</restriction>
			</simpleContent>
		</complexType>
	</element>

	<element name="bnRef" substitutionGroup="mx:ref">
		<annotation>
			<documentation>
				A list of one or more references to this method in &quot;The Bell News&quot;.
			</documentation>
		</annotation>
		<complexType>
			<simpleContent>
				<restriction base="mx:journalRefType">
					<pattern value="V?\d+/\d+(\s(V?\d+/)?\d+)*"></pattern>
					<attribute name="journal" type="normalizedString" fixed="The Bell News" />
				</restriction>
			</simpleContent>
		</complexType>
	</element>

	<element name="cbRef" substitutionGroup="mx:ref">
		<annotation>
			<documentation>
				A list of one or more references to this method in &quot;Church Bells&quot;.
			</documentation>
		</annotation>
		<complexType>
			<simpleContent>
				<restriction base="mx:journalRefType">
					<pattern value="V?\d+/\d+(\s(V?\d+/)?\d+)*"></pattern>
					<attribute name="journal" type="normalizedString" fixed="Church Bells" />
				</restriction>
			</simpleContent>
		</complexType>
	</element>

	<element name="tdmmRef" substitutionGroup="mx:ref">
		<annotation>
			<documentation>Numerical index in the Treble Dodging Minor Methods collection</documentation>
		</annotation>
		<complexType>
			<simpleContent>
				<restriction base="mx:refType">
					<pattern value="\d+"></pattern>
				</restriction>
			</simpleContent>
		</complexType>
	</element>

	<element name="pmmRef" substitutionGroup="mx:ref">
		<annotation>
			<documentation>Numerical index in the Plain Minor Methods collection</documentation>
		</annotation>
		<complexType>
			<simpleContent>
				<restriction base="mx:refType">
					<pattern value="\d+"></pattern>
				</restriction>
			</simpleContent>
		</complexType>
	</element>

	<!--                 Performance References defined by this schema             -->

	<element name="performance" type="mx:performanceType" abstract="true">
		<annotation>
			<documentation>
				This is the abstract definition of a performance reference. This schema defines a number of concrete
				references. Users can define their own references in their own namespaces and adding them to the mx:
				performance substitution group
			</documentation>
		</annotation>
	</element>

	<element name="firstTowerbellPeal" type="mx:performanceType" substitutionGroup="mx:performance">
		<annotation>
			<documentation>Details of the first single-method tower bell peal of this method</documentation>
		</annotation>
	</element>

	<element name="firstHandbellPeal" type="mx:performanceType" substitutionGroup="mx:performance">
		<annotation>
			<documentation>Details of the first single-method handbell peal of this method</documentation>
		</annotation>
	</element>
	
	<element name="firstInclusionInTowerbellPeal" type="mx:performanceType" substitutionGroup="mx:performance">
		<annotation>
			<documentation>Details of the first tower bell peal that includes this method</documentation>
		</annotation>
	</element>

	<element name="firstInclusionInHandbellPeal" type="mx:performanceType" substitutionGroup="mx:performance">
		<annotation>
			<documentation>Details of the first handbell peal that includes this method</documentation>
		</annotation>
	</element>
	

	<element name="firstTowerbellExtent" type="mx:performanceType" substitutionGroup="mx:performance">
		<annotation>
			<documentation>Details of the first extent of this method rung on tower bells</documentation>
		</annotation>
	</element>
	
	<element name="firstHandbellExtent" type="mx:performanceType" substitutionGroup="mx:performance">
		<annotation>
			<documentation>Details of the first extent of this method rung on handbells</documentation>
		</annotation>
	</element>

	<!--                 Types used by these definitions              -->

	<complexType name="refType">
		<simpleContent>
			<extension base="string">
				<attribute name="id" type="ID" />
				<anyAttribute namespace="##any" processContents="lax" />
			</extension>
		</simpleContent>
	</complexType>

	<complexType name="journalRefType">
		<simpleContent>
			<restriction base="mx:refType">
				<attribute name="journal" type="normalizedString" />
			</restriction>
		</simpleContent>
	</complexType>

	<complexType name="performanceType">
		<all>
			<element name="date" type="date" minOccurs="0" />
			<element name="location" type="mx:locationType" minOccurs="0" />
			<element name="society" type="normalizedString" minOccurs="0" />
			<element ref="mx:references" minOccurs="0" />
		</all>
		<attribute name="id" type="ID" />
		<anyAttribute namespace="##other" processContents="lax" />
	</complexType>

	<complexType name="locationType">
		<all>
		    <element name="room" type="normalizedString" minOccurs="0" />
			<element name="building" type="normalizedString" minOccurs="0" />
			<element name="address" type="normalizedString" minOccurs="0" />
			<element name="town" type="normalizedString" minOccurs="0" />
			<element name="county" type="normalizedString" minOccurs="0" />
		<element name="region" type="normalizedString" minOccurs="0" />
			<element name="country" type="normalizedString" minOccurs="0" />
		</all>
		<attribute name="id" type="ID" />
		<anyAttribute namespace="##other" processContents="lax" />
	</complexType>

	<simpleType name="pathType">
		<list itemType="positiveInteger" />
	</simpleType>

	<simpleType name="fixedType">
		<restriction base="string">
			<pattern value="\w+" />
		</restriction>
	</simpleType>

	<simpleType name="leadHeadCodeType">
		<restriction base="string">
			<pattern value="[abefghlm]|[cdjkpqrs]\d*" />
		</restriction>
	</simpleType>

	<complexType name="fchGroupType">
		<simpleContent>
			<extension base="mx:fchGroupString">
				<attribute name="affected" type="mx:affectedType" default="234"></attribute>
			</extension>
		</simpleContent>
	</complexType>

	<simpleType name="fchType">
		<list itemType="mx:rowType" />
	</simpleType>

	<simpleType name="fchGroupString">
		<restriction base="string">
			<pattern
				value="A?B?C?D?E?F?G?H?I?K?(L|((L1)?(L2)?))M?N?O?(P|((P1)?(P2)?))R?S?T?(U|((U1)?(U2)?))(/(B?C?D?E?F?H?(K|((K1)?(K2)?))(N|((N1)?(N2)?))O?T?))?(a|((a1)?(a2)?))?b?c?d?e?f?X?Y?Z?" />
		</restriction>
	</simpleType>

	<simpleType name="affectedType">
		<restriction base="string">
		   <pattern value="([A-HJ-NP-WYZa-hj-np-wyz0-9]|\{\d+\})+" />
              <length value="3" />
		</restriction>
	</simpleType>

	<simpleType name="symmetryType">
		<restriction base="string">
			<enumeration value="palindromic" />
			<enumeration value="rotational" />
			<enumeration value="double" />
		</restriction>
	</simpleType>

	<!--                 Place Notation                    -->

	<complexType name="notationType">
		<simpleContent>
			<extension base="mx:placeNotationType">
				<attribute name="sym" type="boolean" default="true" />
			</extension>
		</simpleContent>
	</complexType>


	<simpleType name="placeNotationType">
		<annotation>
			<documentation>
				A sequence of changes. Each change is represented using conventional place notation, in which positions
				1 to 9 are represented using their digit, 10 by 0, 11 by E, 12 by T, 13-16 by A-D, 17-19 by F-H, 20-24
				by J-N, 25-28 by P-S, 29-31 by U-W, 32-33 by Y-Z (lower case letters are also permitted and are
				interpreted as equivalent to their upper case counterparts). In addition positions may be represented as
				{nnn} where nnn is a positive integer, so T is equivalent to {12}. The . character is used to separate
				the changes in the sequence. It may be omitted before or after -
			</documentation>
		</annotation>
		<restriction base="string">
			<pattern
				value="(\-|(\{\d+\}|[A-HJ-NP-WYZa-hj-np-wyz0-9])+)(\.?(\-|(\{\d+\}|[A-HJ-NP-WYZa-hj-np-wyz0-9])+))*(,(\-|(\{\d+\}|[A-HJ-NP-WYZa-hj-np-wyz0-9])+)(\.?(\-|(\{\d+\}|[A-HJ-NP-WYZa-hj-np-wyz0-9])+))*)?" />
		</restriction>
	</simpleType>

	<simpleType name="rowType">
		<restriction base="string">
			<pattern value="([A-HJ-NP-WYZa-hj-np-wyz0-9]|\{\d+\})+" />
		</restriction>
	</simpleType>

</schema>
