Here is my desired setup:
- I want to model a Course.
- The base definition should be just the information for a Course: it has a Department, a Number, a number of Credits, a Title, and a Description.
- Optionally, I want the ability to group several Course elements under a Courses element. This container should be able to specify the Department attribute, which should mean that all contained Course elements inherit that value (and are not allowed to redeclare the Department value in instance documents)
- I want to allow the Courses element to optionally contain other Courses elements, so if the author of an instance document wants a root Courses element, and then several Courses elements within that--each with their own Department attribute specified--this could be done
Code: Select all
<xs:element name="course" type="courseType" />
<xs:element name="courses" type="coursesType" />
Now, define all TYPES.
(If unsure whether to write a type or an element, go with the type.
You can always make an element based off of that type definition.)
<xs:element ref="course" minOccurs="1" maxOccurs="unbounded">
<xs:attribute name="dept" type="xs:IDREF" use="required" />
<xs:attributeGroup ref="course-attributes" />
<xs:keyref name="dept" refer="deptKey">
This is where I got stuck in my schema. I was adding in the Courses definition when I couldn't figure out how to redefine restrictions, or give the ability to contained Course elements to inherit their Department value from their parent Courses element.
Could somebody show me how this is done?