Workshops --> XML --> Demo --> schema7.html
SLIS@IU logo

L595 XML@IU logo

Creating Schemas

Simple types

Using facets, it is possible to set a range of values that will be allowed in an element

This is an example of the enumeration facet which allows a list of acceptable values to be specified

The generic form is

<xsd:element name="name">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="value #1"/>
            <xsd:enumeration value="value #2"/>
            <xsd:enumeration value="value #3"/>
            <xsd:enumeration value="value #4"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

An example is

<xsd:element name="student_status">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="freshman"/>
            <xsd:enumeration value="sophomore"/>
            <xsd:enumeration value="junior"/>
            <xsd:enumeration value="senior"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

Notice that this simple type is defined as belonging to an element called "student_status"

This means that it can only be used with that element

So these are all acceptable in the XML document

<student_status>freshman</student_status>
<student_status>
junior</student_status>
<student_status>
senior</student_status>

This is not acceptable

<student_status>graduate</student_status>

This is a useful facet that can be used with all simple types except for boolean

Home
schema schema 2 schema 3 schema 4 schema 5 schema 6 schema 7 schema 8 schema 9
Next

schema 10 schema 11 schema 12 schema 13 schema 14 schema 15 schema 16 schema 17

Page by Howard Rosenbaum
Find me at hrosenba@indiana.edu You are here: http://www.slis.indiana.edu/hrosenba/www/Workshops/XML/Demo/schema7.html