Brandon Daley
Brandon Daley

Reputation: 1

XML Schema Definition for Class Schedule

So, I am tasked to write an XML Schema Definition to store my current semester's academic schedule. I am supposed to include my name and class year as well as additional elements for each of my academic classes. I need to enforce rules that I must have at least four classes and no more than eight classes. For each class, I need a designator, the course name, the instructor name, and current overall percentage. I also need to make sure they are all the appropriate data type.

My issue seems to lie in putting in part for the name and class year. Currently, I have:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="classSchedule">               
    <xs:complexType>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="classYear" type="xs:int"/>
            <xs:sequence minOccurs="4" maxOccurs="8">
                <xs:element name="class">
                    <xs:complexType>
                        <xs:all>
                            <xs:element name="courseDesignator" type="xs:string"/>
                            <xs:element name="courseName" type="xs:string"/>
                            <xs:element name="instructorName" type="xs:string"/>
                            <xs:element name="currentGrade" type="xs:float"/>
                        </xs:all>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>       
    </xs:element>
</xs:schema>

Right now, I get an error that the sequence tag cannot come underneath the complexType tag.

The name and class year are info about the student, and each student will have between 4 and 8 classes; right now I can't figure out why I am having trouble putting in the name and class year. When I take out the two lines for name and class year, the XSD saves properly without errors.

Upvotes: 0

Views: 870

Answers (1)

Alan
Alan

Reputation: 3417

Your schema is mostly fine, however the definition of a complexType node requires the attributes to come after the sequence. E.g.:

<xs:complexType>
  <xs:sequence minOccurs="4" maxOccurs="8">
    <xs:element name="class">
      <xs:complexType>
        ...
      </xs:complexType>
    </xs:element>
  </xs:sequence>
  <xs:attribute name="name" type="xs:string"/>
  <xs:attribute name="classYear" type="xs:int"/>
</xs:complexType>

Upvotes: 1

Related Questions