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

"Hello world!" Example of XSD

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

Before getting into details of XML Schema specifications, let's look at a simple example of XSD (a XML schema written in XML Schema language). Here is the content of the XSD example file, hello.xsd:

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

Note that:

  • This XSD file is a true XML document with the root element named as "schema".
  • This XSD file contains one "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 "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 validat hello.xml against hello.xsd:

  • 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.

Sections in This Chapter

What Is XML Schema?

"Hello world!" Example of XSD

XML Schema Processors

Dr. Herong Yang, updated in 2007
"Hello world!" Example of XSD