Validate an XML Document with XML Schema

XML Schema is the W3C evolution of the DTD. It is complex but powerful, in wide use but not always popular. This hack will help you start writing schema in this format.

XML Schema is a recommendation of the W3C, written in three parts. Part 0 is a nice little primer ( that gets you started with the language. Part 1 describes the structures of XML Schema (; it is a long spec—about 200 pages long when printed—and is rather complex. Part 2 defines datatypes ( and has been more gladly received than Part 1, though it is considered by some to be ad hoc and not without anomalies.

XML mensch James Clark ( has said of Part 1 that “it is without doubt the hardest to understand specification that I have ever read” ( Many others who have read the spec, or have attempted to read it, heartily agree with James. This is unfortunate, as it has placed many schema writers and companies in the uncomfortable position of using and supporting a difficult spec from the W3C, a widely accepted (though not always highly regarded) source. Happily, there are alternatives, such as RELAX NG [Hack #72] and tools such as Trang (, that can conveniently convert RELAX NG to XML Schema [Hack #76] .

A Quick Introduction to XML Schema

We’ll start ...

Get XML Hacks now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.