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

L595 XML@IU logo

Creating Schemas

Writing the schema

The schema begins with a XML declaration

<?xml version="1.0"?>

The next line is the schema declaration

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

This declaration identifies the file that defines the general components of the schema language in use

It is also called the schema of schemas

Then a namespace is declared in one of two ways

A target namespace is used to specify a specific location where the elements used in this particular schema are defined

It is specified as part of the opening namespace declaration and allows all locally declared elements and attributes to be associated with the namespace

targetNamespace="http://formxml.org"
elementFormDefault="qualified">
attributeFormDefault="qualified">

In context, it is:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.formxml.org/memo.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified">

Or, a URL is provided to direct the parser to a specific namespace

<memo xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance
xsi:NamespaceSchemaLocation="http://somewhere.org/MEMO/memo.xsd>
"

Note that the schema file has an .xsd extension

This form of a namespace prevents collisions among global elements so that the same element name can be used in different schema with different meanings

Then come the datatypes that constitute the schema

These can be simple or complex types and are discussed in the next pages

Schema, like other markup files, can include comments

The generic form of a comment contains text, which is enclosed in an xsd:documentation container, which itself is enclosed in an xsd:annotation container:

<xsd:annotation>
    <xsd:documentation>

      This schema hurts my brain real bad
    </xsd:documentation>
</xsd:annotation>

Comments can be used anywhere in the schema

Calling a schema from an XML document

The generic call is:

<root_element
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://address.of.the.schema/file.xsd">

Here's how simple types are defined

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