Go to previous pageGo to next page

1.4.2. XML Schema

important

In this chapter we mention XML namespaces. If you do not know namespaces and their functions and you want to get familiar with this topic, have a look at the W3C Tutorial "XML Namespaces". There, you will find the needed information.

The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD.

An XML Schema defines:

  • elements that can appear in a document,
  • attributes that can appear in a document,
  • which elements are child elements,
  • the order of child elements,
  • the number of child elements,
  • whether an element is empty or can include text,
  • data types for elements and attributes,
  • default and fixed values for elements and attributes.
question

What do XML Schemas look like?

We introduce you the XML Schema corresponding to the following XML document:

XML DocumentXML Document

As you learnt in a former chapter, the corresponding DTD file "person.dtd" looks like this:

Content      of the DTD file "person.dtd"Content of the DTD file "person.dtd"

The XML Schema file called "person.xsd" that defines the elements of the XML document above, looks like this (move mouse over the coloured rectangles to get information about the functions of the different elements):

Content of the file "person.xsd"

The person element is said to be of a complex type because it contains other elements. The other elements (age, gender, name) are said to be simple types because they do not contain other elements.

The reference to an XML Schema in an XML document looks as following (move mouse over the coloured rectangles to get information about the functions of the different elements):

Reference to an XML Schema

If you want to get familiar with the definition of simple XML Schema elements or attributes have a look at the W3C Tutorial "Learn XML Schema" chapters "XSD Elements" and "XSD Attributes". Of course, you are free to watch the other chapters as well ;-).



Go to previous page
Go to next page