XML Schema Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.00

Schema and Schema XML Representation

This section describes what is a schema and what is a schema XML representation.

What is a schema? A schema is a container for schema components that defines a set of rules to which an XML document must conform in order to be considered 'valid' according to that schema. There are 7 types of schema components that mentioned in the XML Schema specification:

  • Named type definition component - Defines a named simple or complex datatype.
  • Attribute declaration component - Declares an attribute to be used in element declarations.
  • Element declaration component - Declares an XML element for the XML document to be validated.
  • Named attribute group definition component - Defines a named attribute group.
  • Name model group definition component - Defines a named model group.
  • Notation declaration component - Declares a notation.

A schema can be represented in XML by one or more schema documents, commonly called XSD (XML Schema Definition) documents

In another word, a schema XML document, XSD file, may contain one complete schema, or a part of one schema.

For example, the following XML document, hello.xsd, is the XML representation, XSD document, of a schema which contain only 1 component, an element declaration component that defines a validation rule for the XML document to be validated.

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:element name="p" type="xsd:string"/>
</xsd:schema>

Apparently, the validation rule defined in hello.xsd says that the XML document to be validated can have a root element named as "p" with no attributes and no sub (child) elements. But it can have a "string" as its text content.

Base this concept, the more technically correct definition of an XSD document should be:

What is an XSD document? An XSD document is the XML representation of an XML schema, or a part of an XML schema, expressed in XML Schema language.

Sections in This Chapter

Schema and Schema XML Representation

Checking Schema Documents - XsdSchemaChecker.java

Creating Schema Documents - "schema" Element

Declaring Root Elements - "element" Element

Specifying Element Datatype - "type" Attribute

Using XML Schema Built-in Datatypes

Using XML Schema Built-in Datatypes Incorrectly

Validating XML Documents again Schema Documents

Deriving New Simple Datatypes - "simpleType" Element

Defining Complex Datatypes - "complexType" Element

Validation Error Examples on Complex Datatypes

Dr. Herong Yang, updated in 2007
Schema and Schema XML Representation