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

L595 XML@IU logo

Creating Schemas

Simple types

Here are some other ways to limit and specify content of elements using simple types

Use the attribute length to set an exact number of characters (non-negative integers) that can appear in an element

The generic form is:

<xsd:element name="name">
    <xsd:simpleType>
        <xsd:restriction base="value">
            <xsd:length value="value"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

An example is:

<xsd:element name="alien_probes">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:length value="6"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

This is a valid example of content in the XML file

<alien_probes>!ouch!</alien_probes>

This is not valid

<alien_probes>!ouch it hurts!</alien_probes>

Here are some commonly used attributes that can restrict the content of elements

minLength defines the minimum number of characters that can be used in an element

maxLength defines the maximum number of characters that can be used in an element

minExclusive defines a range of acceptable values greater than but not equal to the specified value

precision and scale to limit the number of digits in an integer

precision sets the maximum number of digits in the integer

scale sets the maximum number of digits to the right of the decimal point

The generic form is:

<xsd:element name="name">
    <xsd:simpleType>
        <xsd:restriction base="value">
            <xsd:precision value="value"/>
            <xsd:scale value="value"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

An example is

<xsd:element name="alien_probes">
    <xsd:simpleType>
        <xsd:restriction base="xsd:decimal">
            <xsd:precision value="4"/>
            <xsd:scale value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

This is a valid example of content in the XML file

<alien_probes>52.55</alien_probes>

This is not valid

<alien_probes>52.555</alien_probes>

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