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

L595 XML@IU logo

Creating Schemas

Simple types

This is an element that can contain only text strings

In a DTD, we used <#PCDATA> to represent a text string as the content of an element

The content could take any number of forms (numbers, letters, dates...)

In schemas, simple types can use a predefined set of datatypes to specify text or numeric content

There are also facets that can be used to further restrict these elements

Two examples are 9 digit zip codes or telephone numbers

The generic form of a simple type is:

<xsd:element name="somename" type="datatype"/>

In an XML document, the corresponding element would look like this:

<somename>content</somename>

Here is a subset of the available datatypes that can be used

Datatype
Meaning
xsd:string
Alphanumeric characters
xsd:decimal
Numbers with decimal points
xsd:boolean
Contains conditional stratement (true/false; 0/1)
xsd:uri-reference
Contains a URL
xsd:date
Year, month, day
xsd:time
Hours, minutes, seconds
xsd:language
Two character ISO language code
custom
One you make up

The <xsd:time> datatype can be broken down to include more specific content

Time datatype
Meaning
Format
Schema example
As XML
xsd:time
Greenwich mean time: EST is UTC-5
hh:mm:ss.sssUTC_time_zone
<xsd:element name="alien_visit" type="xsd:time"/>
<alien_visit>22:15-35-14</alien_visit>
xsd:duration
A bounded period of time
PYrMoDTHrMmSs
<xsd:element name="alien_visit" type="xsd:duration"/>
<alien_visit>P4D</alien_visit>
xsd:timeinstant
A specific moment
Full_yr-Mo-DTHrMmSs
<xsd:element name="alien_visit" type="xsd:timeinstant"/>
<alien_visit>1960-07-08T-519:22:45.32</alien_visit>
xsd:date
A specific date
Full_yr-Mo-D
<xsd:element name="alien_visit" type="xsd:date"/>
<alien_visit>1960-07-08</alien_visit>
xsd:gYearMonth
A specific month
Full_yr-Mo
<xsd:element name="alien_visit" type="xsd:gYearMonth"/>
<alien_visit>1960-07</alien_visit>
xsd:gYear
A specific year
Full_yr
<xsd:element name="alien_visit" type="xsd:gYear"/>
<alien_visit>1960</alien_visit>
xsd:recurringDate
A specific day in a specific month without the year
--Mo-D
<xsd:element name="alien_visit" type="xsd:recurringDate"/>
<alien_visit>--08-23</alien_visit>
xsd:recurringDay
A specific day without the year and month
---D
<xsd:element name="alien_visit" type="xsd:recurringDay"/>
<alien_visit>---15</alien_visitt>

There is also a set of datatypes for working with numbers

Number datatype
Meaning
Format
Schema example
As XML
xsd:decimal
Positive or negative numbers
#, -#, #.##
<xsd:element name="alien_visit" type="xsd:decimal"/>
<alien_visit>45.3</alien_visit>
xsd:integer
Positive or negative whole numbers
#, -#
<xsd:element name="alien_visit" type="xsd:integer"/>
<alien_visit>62</alien_visit>
xsd:positiveInteger
Only positive whole numbers
#
<xsd:element name="alien_visit" type="xsd:positiveInteger"/>
<alien_visit>165</alien_visit>
xsd:negativeInteger
Only negative whole numbers
-#
<xsd:element name="alien_visit" type="xsd:negativeInteger"/>
<alien_visit>-13</alien_visit>
xsd:nonNegativeInteger
Only positive whole numbers (not "0")
#
<xsd:element name="alien_visit" type="xsd:nonNegativeInteger"/>
<alien_visit>45</alien_visit>
xsd:nonPositiveIntegers
Only negative numbers (not "0")
-#
<xsd:element name="alien_visit" type="xsd:nonPositiveIntegers"/>
<alien_visit>-35</alien_visit>

It is also possible to create custom simple datatypes

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