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

L595 XML@IU logo

Creating Schemas

Simple types

Custom simple types combine features from existing datatypes and provide more control over the specification of content of elements in the schema

They can be defined with sets of restrictions and specific patterns that define acceptable content

Custom simple types are defined globally and can be reused throughout the schema

The generic form is

<xsd:simpleType name="nameType">
    <xsd:restriction base="xsd:string">
        <xsd:pattern value="values" />
    </xsd:restriction>
</xsd:simpleType>

The name that is referenced in the opening declaration is the name of the simpleType and not the element in which it will be used

An example is

<xsd:simpleType name="statusType">
    <xsd:restriction base="xsd:string">
        <xsd:pattern value="freshman | sophomore | junior | senior" />
    </xsd:restriction>
</xsd:simpleType>

The xsd:restriction base is used to specify the datatype that will be used as the basis for the custom simple type

Once this custom simple type has been defined, it can be used in the definition of other elements in the schema

This means that this simpletype has been defined globally

It has been named (statusType) and can be called by that name anywhere in the schema

This is how it could be used

<xsd:element name="student" type="statusType">

This is how it would be used in the XML file to restrict the range of acceptable content

<student>junior</student>

So because the range of content has been specified in the custom simple type, this is not acceptable

<student>graduate student</student>

An anonymous custom simple type is similar but is local, meaning that it cannot be reused

The generic form is

<xsd:element name="element_name">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="values" />
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

An example is

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

Notice that this anonymous custom simple type has been linked specifically to an element

Also, it has not been named

Using this anonymous custom simple type, 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>

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/schema6.html