1. <?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.cs.utk.edu/~bvz" xmlns="http://www.cs.utk.edu/~bvz" elementFormDefault="qualified"> <xs:element name="catalog"> <xs:complexType> <xs:sequence> <xs:element name="artist" type="artistType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="nameType"> <xs:sequence> <xs:element name="first" type="xs:string"/> <xs:element name="last" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="artistType"> <xs:sequence> <xs:element name="retired" type="xs:boolean"/> <xs:element name="country" type="xs:string"/> <xs:element name="name" type="nameType"/> <xs:element name="cd" type="cdType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="cdType"> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="company" type="xs:string"/> <xs:element name="price" type="priceType"/> <xs:element name="yearReleased" type="yearReleasedType"/> <xs:element name="dateAcquired" type="dateAcquiredType"/> </xs:sequence> </xs:complexType> <xs:simpleType name="dateAcquiredType"> <xs:restriction base="xs:string"> <xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{2}"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="yearReleasedType"> <xs:restriction base="xs:positiveInteger"> <xs:minExclusive value="1900"/> <xs:maxExclusive value="2006"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="priceType"> <xs:restriction base="xs:decimal"> <xs:totalDigits value="4"/> <xs:fractionDigits value="2"/> <xs:minExclusive value="0"/> <xs:maxExclusive value="100"/> </xs:restriction> </xs:simpleType> </xs:schema>
    1. <!ELEMENT payroll (employee*)> <!ELEMENT employee (name, spouse?, child*, tax-status, ssn, salary, date-of-birth, (manager | staff))> <!ELEMENT name (first, middle?, last)> <!ELEMENT first (#PCDATA)> <!ELEMENT middle (#PCDATA)> <!ELEMENT last (#PCDATA)> <!ELEMENT spouse (first, middle?, last)> <!ELEMENT child (first, middle?, last)> <!ELEMENT tax-status (#PCDATA)> <!ELEMENT ssn (#PCDATA)> <!ELEMENT salary (#PCDATA)> <!ELEMENT date-of-birth (#PCDATA)> <!ELEMENT manager (group, yrsAtRank)> <!ELEMENT group (#PCDATA)> <!ELEMENT yrsAtRank (#PCDATA)> <!ELEMENT staff (skill+)> <!ELEMENT skill (#PCDATA)>
    2. <?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.cs.utk.edu/~bvz/payroll" xmlns="http://www.cs.utk.edu/~bvz/payroll" elementFormDefault="qualified"> <xs:element name="payroll"> <xs:complexType> <xs:sequence> <xs:element name="employee" type="employeeType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="employeeType"> <xs:sequence> <xs:element name="name" type="nameType" /> <xs:element name="spouse" type="nameType" minOccurs="0" maxOccurs="1" /> <xs:element name="child" type="nameType" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="tax-status" type="taxStatusType"/> <xs:element name="ssn" type="ssnType" /> <xs:element name="salary" type="salaryType" /> <xs:element name="date-of-birth" type="xs:date"/> <xs:choice> <xs:element name="manager" type="managerType" /> <xs:element name="staff" type="staffType" /> </xs:choice> </xs:sequence> </xs:complexType> <xs:simpleType name="taxStatusType"> <xs:restriction base="xs:string"> <xs:enumeration value="married"/> <xs:enumeration value="single"/> <xs:enumeration value="headOfHousehold"/> <xs:enumeration value="separated"/> </xs:restriction> </xs:simpleType> <xs:complexType name="nameType"> <xs:sequence> <xs:element name="first" type="firstNameType"/> <xs:element name="middle" type="middleNameType" minOccurs="0" maxOccurs="1"/> <xs:element name="last" type="lastNameType"/> </xs:sequence> </xs:complexType> <xs:simpleType name="firstNameType"> <xs:restriction base="xs:string"> <xs:pattern value="[A-Z][A-Za-z \-]{0,14}"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="middleNameType"> <xs:restriction base="xs:string"> <xs:pattern value="[A-Z]"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="lastNameType"> <xs:restriction base="xs:string"> <xs:pattern value="[A-Z][A-Za-z \-]{0,19}"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="ssnString"> <xs:restriction base="xs:string"> <xs:pattern value="[0-9]{3}-[0-9]{2}-[0-9]{4}"/> </xs:restriction> </xs:simpleType> <xs:complexType name="ssnType"> <xs:simpleContent> <xs:extension base="ssnString"> <xs:attribute name="type" type="ssnTypeAttribute" default="original" /> </xs:extension> </xs:simpleContent> </xs:complexType> <xs:simpleType name="ssnTypeAttribute"> <xs:restriction base="xs:string"> <xs:enumeration value="assigned"/> <xs:enumeration value="original"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="yrsAtRankType"> <xs:restriction base="xs:nonNegativeInteger"> <xs:minInclusive value="0"/> <xs:maxInclusive value="50"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="salaryType"> <xs:restriction base="xs:decimal"> <xs:totalDigits value="9"/> <xs:fractionDigits value="2"/> <xs:minInclusive value="0"/> <xs:maxInclusive value="2000000"/> </xs:restriction> </xs:simpleType> <xs:complexType name="managerType"> <xs:sequence> <xs:element name="group" type="xs:string"/> <xs:element name="yrsAtRank" type="yrsAtRankType"/> </xs:sequence> <xs:attribute name="title" type="xs:string" use="required" /> </xs:complexType> <xs:complexType name="staffType"> <xs:sequence> <xs:element name="skill" type="xs:string" minOccurs="1" maxOccurs="5"/> </xs:sequence> </xs:complexType> </xs:schema>
  2. My solution may differ from yours. However, here was my thought process that drove my design:

    1. The exam seems to consist of two general parts: a set of instructions and a set of questions. So I created tags for instructions and questions. Each of the parts formed a group, so I created children elements for each group, namely an instruction and a question.
    2. The instructions were optional, so if they appeared, there needed to be at least one of them.
    3. There should be at least one question since how can there be an exam without a question?
    4. The questions had a couple of common elements, namely a prologue that introduced the question and a point value. Hence I created tags for the prologue and the points and made these tags children of a question.
    5. The questions seemed to fall into three categories: 1) essay type questions, 2) matching questions, and 3) true/false style questions (the true/false question was is this statement correct or incorrect, which can also be thought of as true or false). Hence I made these three types of questions into alternative elements for a question.
    6. All three types of questions had a subpart, so I created a subpart tag.
    7. Each subpart of an essay question had a question and an answer, so I created tags for both. Since I already had a question tag, I called the question part a questionStatement.
    8. A matching question had a set of choices followed by a set of subparts. Each subpart had a question and an answer. Hence I created a choices tag and gave it one or more choice elements. For the subpart I had tags for the question statement and the answer.
    9. A trueFalseQuestion had one or more subparts. Each subpart had a question and an answer, so I created tags for a question statement and an answer.
    10. When I was done I had the same subpart structure for each type of question. For a DTD I would have created a separate element for the subpart, and used it in all three questions. If I had been forced to create a schema, I might have assigned different types to some of the answers, and hence had to define three different types of subparts. For example, might have only allowed "true" or "false" as the answer for a true-false question. I schema allows me to create elements with the same name but different types, so long as they appear in different contexts.
        essayQuestion | matchingQuestion | trueFalseQuestion
              answer  // the choice that was made
              answer  // correct or incorrect