XSD Tutorials - Herong's Tutorial Examples - Version 5.10, by Dr. Herong Yang

"Hello world!" Example of XSD

This section describes a simple example of XSD called 'Hello World'.

Before getting into details of XSD specifications, let's look at a simple example of an XML schema defined in XSD language, hello.xsd:

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

Note that:

  • This XSD file is a true XML document with the root element named as "schema".
  • This XSD file contains one single "Element Declaration" statement <element ...>.
  • The "Element Declaration" statement declares that the conforming XML documents must have a root element named as "p".
  • The "Element Declaration" statement also declares that the root element "p" should have content of XSD "string" type.

Obviously, hello.xsd is a very simple XML schema. Writing an XML document that conforms to hello.xsd is easy. There is an example, hello.xml

<?xml version="1.0"?>
<p>Hello world!</p>

Let's validate hello.xml against hello.xsd manually:

  • hello.xml has a root element of "p" which matches the name declared in hello.xsd.
  • The content of "p" is a string, "Hello world!", which matches the datatype declared in hello.xsd.

Now we can say that hello.xml is a valid document, conforming to hello.xsd.

Last update: 2013.

Table of Contents

 About This Book

Introduction to XML Schema

 What Is XSD (XML Schema Definition)?

"Hello world!" Example of XSD

 XML Schema Processors

 XML Editor and Schema Processor - XMLPad

 Java API for XML Processing - JAXP

 JAXP - XML Schema (XSD) Validation

 Xerces2 Java Parser - Java API of XML Parsers

 Using Xerces2 Java API

 XML Schema Language - Basics

 Introduction of XSD Built-in Datatypes

 "string" and Its Derived Datatypes

 "decimal" and Its Derived Datatypes

 "dateTime" and Its Related Datatypes

 Miscellaneous Built-in Datatypes

 Facets, Constraining Facets and Restriction Datatypes

 "simpleType" - Defining Your Own Simple Datatypes

 Complex Element Declaration

 Identity-Constraints: unique, key and keyref

 Assertion as Custom Validation Rules

 XML Schema Location and Namespace in XML Documents

 Overriding Element Types in XML Documents

 Linking Multiple Schema Documents Together



 PDF Printing Version

"Hello world!" Example of XSD - Updated in 2014, by Dr. Herong Yang