This version of the Ed-Fi Data Standard is no longer supported. See the Ed-Fi Technology Version Index for a link to the latest version.

 

How To: Extend the Ed-Fi XML Schema (Part 2)

Customizing by Using XML Complex Type Restriction


XML schema syntax supports the restriction of complex types that can be used to:

  • Eliminate optional attributes or associations
  • Set optional attributes or associations to mandatory

To illustrate this capability, consider an interchange that carries a final high school student academic record that includes a class-ranking element. If no customizations were required, this graduation interchange schema would be constructed as follows:

<?xml version=”1.0” encoding=”UTF-8”?>
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema” xmlns=”http://ed-fi.org/0200” targetNamespace=”http://ed-fi.org/0200-RFC” elementFormDefault=”qualified” attributeFormDefault=”unqualified”>
     <xs:include schemaLocation=”Ed-Fi-Core.xsd”/>
     <xs:element name=”GraduationInterchange”>
         <xs:complexType>
              <xs:choice maxOccurs=”unbounded”>
                  <xs:element name=”StudentAcademicRecord” type=”StudentAcademicRecord”/>
              </xs:choice>
         </xs:complexType>
     </xs:element>
</xs:schema>

The base, unmodified Ed-Fi Schema for ClassRanking is shown below:

XML Schema listing for ClassRanking

<xs:complexType name=”ClassRanking”>
	<xs:sequence>
		<xs:element name=”ClassRank” type=”xs:int”/>
		<xs:element name=”TotalNumberInClass” type=”xs:int”/>
		<xs:element name=”PercentageRanking” type=”xs:int” minOccurs=”0”/>
		<xs:element name=”ClassRankingDate” type=”xs:date” minOccurs=”0”/>
	</xs:sequence>
</xs:complexType>

For this example, customize ClassRanking and StudentAcademicRecord as follows:

  • ClassRanking:
    • Remove the optional element ClassRankingDate.
    • Change the optional element PercentageRanking to be mandatory.
  • StudentAcademicRecord
    • Remove the optional element ClassRanking

To accomplish this, take the followings steps:

  1. Use the base EXTENSION-Ed-Fi-Extended-Core.xsd, which includes the schema Ed-Fi-Core.xsd, to create the required extensions.
  2. Create a new complex type EXTENSION-ClassRankingRestriction.
    • Note: The EXTENSION- prefix is a convention used in the Ed-Fi Extension Framework to denote custom type definitions.
  3. Define the EXTENSION-ClassRankingRestriction to be a restriction with a base of ClassRanking, as defined in the Ed-Fi-Core.xsd.
  4. Within the restriction, define a sequence and restate the elements that exactly match those defined in ClassRanking and in the same order, with the exception of:
    • Omit the minOccurs=”0” in the definition of PercentageRanking
    • Omit the element for ClassRankingDate
  5. Define an EXTENSION-StudentAcademicRecordRestriction to be a restriction with base of StudentAcademicRecord, as defined in Ed-Fi-Core.xsd
  6. Within the restriction, define a sequence and restate the elements that exactly match those defined in StudentAcademicRecord and in the same order, with the exception of omitting the ClassRanking element

The following is the resulting schema with annotations removed for brevity:

<?xml version="1.0" encoding="UTF-8"?>
<!-- (c)2015 Ed-Fi Alliance, LLC. All Rights Reserved. -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://ed-fi.org/0200" targetNamespace="http://ed-fi.org/0200" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:include schemaLocation="Ed-Fi-Core.xsd"/>
	<xs:annotation>
		<xs:documentation>===== Ed-Fi 2.0 Extensions =====</xs:documentation>
	</xs:annotation>
	<xs:annotation>
		<xs:documentation>===== Domain Entities =====</xs:documentation>
	</xs:annotation>
	<xs:complexType name="EXTENSION-StudentAcademicRecordRestriction">
		<xs:complexContent>
			<xs:restriction base="StudentAcademicRecord">
				<xs:sequence>
					<xs:element name="CumulativeEarnedCredits" type="Credits" minOccurs="0"/>
					<xs:element name="CumulativeAttemptedCredits" type="Credits" minOccurs="0"/>
					<xs:element name="CumulativeGradePointsEarned" type="GPA" minOccurs="0"/>
					<xs:element name="CumulativeGradePointAverage" type="GPA" minOccurs="0"/>
					<xs:element name="GradeValueQualifier" type="GradeValueQualifier" minOccurs="0"/>
					<xs:element name="AcademicHonor" type="AcademicHonor" minOccurs="0" maxOccurs="unbounded"/>
					<xs:element name="Recognition" type="Recognition" minOccurs="0" maxOccurs="unbounded"/>
					<xs:element name="ProjectedGraduationDate" type="xs:date" minOccurs="0"/>
					<xs:element name="SessionEarnedCredits" type="Credits" minOccurs="0"/>
					<xs:element name="SessionAttemptedCredits" type="Credits" minOccurs="0"/>
					<xs:element name="SessionGradePointsEarned" type="GPA" minOccurs="0"/>
					<xs:element name="SessionGradePointAverage" type="GPA" minOccurs="0"/>
					<xs:element name="Diploma" type="Diploma" minOccurs="0" maxOccurs="unbounded"/>
					<xs:element name="StudentReference" type="StudentReferenceType"/>
					<xs:element name="EducationOrganizationReference" type="EducationOrganizationReferenceType"/>
					<xs:element name="SchoolYear" type="SchoolYearType"/>
					<xs:element name="Term" type="TermDescriptorReferenceType"/>
					<xs:element name="ReportCardReference" type="ReportCardReferenceType" minOccurs="0" maxOccurs="unbounded"/>
				</xs:sequence>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:annotation>
		<xs:documentation>===== Common =====</xs:documentation>
	</xs:annotation>
	<xs:complexType name="EXTENSION-ClassRankingRestriction">
		<xs:complexContent>
			<xs:restriction base="ClassRanking">
				<xs:sequence>
					<xs:element name="ClassRank" type="xs:int"/>
					<xs:element name="TotalNumberInClass" type="xs:int"/>
					<xs:element name="PercentageRanking" type="xs:int"/>
				</xs:sequence>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
</xs:schema>