"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:
<xsd:element name="p" type="xsd:string"/>
- 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
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.
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 APIs
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
Full Version in PDF/EPUB