The "X" in XML stands for "eXtensible" and XML by itself is so extensible that I can invent new elements and attributes as I write my XML documents. The main limit of this extensibility is that I need to keep track of these elements and attributes and that I often need to convey to the applications what I intend to accept in my documents. This is needed for validation purposes and also to automate some of the most time consuming --and boring-- programming tasks. And this is where XML schema languages come to play.

XML Schema languages are a nice idea... as long as they don't add to XML a weight so heavy that XML becomes uneXtensible and, unfortunately, that's what was likely to happen before Relax NG. XML Schema, the dominant XML Schema language, had become so overloaded that it's both difficult to learn, difficult to extend and that its expressive power is too limited to describe all the possibilities offered by XML. Even though we can expect that many applications will accept this overweight, a lightweight and simpler alternative was needed for those of us who want to preserve all the extensibilty of a free style XML.

That's what Relax NG is really:
* a XML schema language
* focused on validating the structure of XML documents
* lightweight enough to be easy to learn, read and write
* powerful enough to describe virtually any vocabulary which is based on well formed XML and conform to namespaces in XML.

There are a couple of reasons why Relax NG is so much easier than W3C XML Schema and both contribute to make it also more reliable and safer to use: Relax NG has a very sound mathematical ground and it has been kept focussed on doing perfectly well a single thing --validating the structure of XML documents. Relax NG won't do the coffee for you, but if you need a schema language easy to use and which won't block you in a labyrinth of obscure limitations this is the language you should be using. Furthermore, an excellent open source tool is available which will convert your Relax NG schemas into other languages including W3C XML Schema.

!!!Who Should Read This Book?

Read this book if you want to:

*Create Relax NG schemas.Status: Need to be updated after a first set of reviews.
*Understand existing Relax NG schemas.
*Discover that XML schema languages can be simple.

To understand this book, you should already have a basic understanding of the structure of XML documents but do not need to know any other XML schema language.

!!!Who Should Not Read This Book?

Do not read this book if you will only be using existing Relax NG schemas to validate XML documents.

!!!Organization of this book

*[Chapter 1:	Relax NG In Perspective|RngBookPerspective] - This chapter gives more perspective on the many aspects of XML validation, what is a schema language and what makes Relax NG really unique.

*[Chapter 2:	Simple Is Beautiful|RngBookPatterns] - This chapter introduces the background of Relax NG itself and insists on the notion of "pattern" which is the elementary building brick on which the whole language is built.

*[Chapter 3:	First Schema|RngBookFirstSchema] - Following the structure of the instance document used all over this book this chapter builds, step by step, a first complete Relax NG schema using the XML syntax.

*[Chapter 4:	Non XML Syntax|RngBookNonXmlSyntax] - The XML syntax is simple, natural and reads almost as plain English but is also verbose. In this chapter we see the alternative compact (non XML) syntax. In the rest of this book, each example will present both the XML and the compact syntaxes so that you can either focus on one of them or learn both of them in parallel.

*[Chapter 5:	Flattening Our First Schema|RngBookFlat] - Our first schema had been following the structure of our instance document in what is called a "Russian doll" design. In this chapter we show how named patterns can be used to limit the depth of a schema, provide re-usability or mimic a DTD.

*[Chapter 6:	More Patterns|RngBookMorePatterns] - Up to now, we have only seen ordered sequences of elements and in this chapter we introduce new compositors to define alternatives and unordered (interleaved) content models.

*[Chapter 7:	Constraining Text Values|RngBookTextPatterns] - In this chapter we introduce the generic mechanism used to constrain text values and the two Relax NG built-in datatypes (namely string and token).

*[Chapter 8:	Datatype Libraries|RngBookTypeLibraries] - In this chapter we see how external datatype libraries may be plugged into Relax NG schemas and spend some type exploring the two datatype libraries which are most frequently used: the W3C XML Schema datatype library and the DTD compatibility datatype library.

*[Chapter 9:	W3C XML Schema Regular Expressions|RngBookWxsRegExp] - One of the most powerful facet which can be used to add constraints on the W3C XML Schema datatype library is the "pattern" facet which relies on its own flavor of regular expressions presented in this chapter.

*[Chapter 10:	Creating Building Blocks|RngBookBuildingBlocks] - Now that we have now all the building blocks, we see in this chapter how we can reuse and redefine them in "grammars" which can be merged.

*[Chapter 11:	Namespaces|RngNamespaces] - We explain briefly what XML namespaces are and discover in this chapter how straightforward is their support in RELAX NG.

*[Chapter 12:	Writing Extensible Schemas|RngBookExtensible] - This chapter covers both the extensibility of the schemas themselves and the extensibility of the class of instance documents described by a schema (in other words, its openness).

*[Chapter 13:	Annotating Schemas|RngBookAnnotations] - Documentation may be targeted to human users but also to other applications and we cover both aspects in this chapter showing for instance how Schematron rules may be embedded in Relax NG schemas, and covering other annotations systems such as Bob DuCharme's schema document pipeline proposal and my own xvif.

*[Chapter 14:	Generating Relax NG schemas|RngBookGeneration] - This chapter explores different sources from which Relax NG can be generated, such as instance documents (Examplotron), UML diagrams, spreadsheets and litterate programming.

*[Chapter 15:	Simplification And Restrictions|RngBookRestrictions] - This chapter goes into the details of the simplification of Relax NG documents described as a normative part of the Relax NG specification which understanding is needed to understand some few obscure limitations.

*[Chapter 16:    Determinism and Datatype Assignment|RngBookAssignment] - One of the strengths of Relax NG is to allow non deterministic schemas. While this is extremely convenient for validation purposes, this is an issue for assigning datatypes to the nodes of the instance documents (a controversial feature out of the scope of Relax NG but used by some applications). This chapter presents the concepts of schema determinism and ambiguity and their impacts on the different ways to use Relax NG schemas.

*[Chapter 17:	Relax NG Elements|RngBookElements] - This chapter is a short reference guide describing all the elements of the XML syntax with their description, synopsis and example.

*[Chapter 18:	Non XML Syntax Reference|RngBookCompact] - This chapter is a short reference guide describing all the elements of the compact syntax with their description, synopsis and example.

*[Chapter 19:	W3C XML Schema Datatypes|RngBookWxsDatatypes] - This chapter is a short reference guide to W3C XML Schema datatypes often used as an external datatype library in Relax NG schemas.

*[Chapter 20:	Glossary|RngBookGlossary] - This chapter is a glossary providing a short explanation of the terms used all over the book.

*[Appendix A: DSDL|RngBookDsdl] - This appendix presents the ISO DSDL project which does include Relax NG as its part 2.

!!!Acknowledgments

I would like to thank the Relax NG OASIS Technical Committee for having provided the subject of this book which would obviously never have been possible without their work and especially Murata Makoto, James Clark and John Cowan for the timely and higly accurate answers they have provided to my many questions.

My own implementation of Relax NG has proven to be most useful in gaining a deep understanding of the language and I would also like to thank Uche Ogbuji who has been my Python mentor during this project and again James Clark for the detailed instructions of how Relax NG can be implemented using the very nice so called "derivative algorithm".

This book is the result of a collaborative work and I thank all the people having contributing comments and annotations, including the tech reviewers, David  Eisenberg, John Cowan and Dave Pawson who have extended their comments well beyond the scope of simple tech reviews and have significantly improved its level of quality. This collaborative work would never have started without my editor, Simon St.Laurent who has believed in this book since before its beginning and just made it happen.

Finally, I need to thank my wife and children for their patience and moral support while I was busy writing this book. Unlike I had done in the preface of my previous book I won't dare to promise that they will recover their husband and father now that this book is over fearing that a new other challenging project might swallow me in a near future!

!!!Powered by WikiML

Most if this book has been edited in a WikiWikiWeb powered by PhpWiki, a PHP implementation of the concept of WikiWikiWeb invented by Ward Cunningham in 1995 and famous for the simplicity of its text based markup. The WikiWikiWeb pages have been converted to XHTML pages using the parser developed by the WikiML project and these pages have been transformed through XSLT into DocBook for production at O'Reilly.

This is probably one of the first attempts to leverage on something as simple to use as a WikiWikiWeb to produce something as complex as a whole book markuped as DocBook and I have been surprised by the smoothness of the whole process.

To learn more about these subjects:

* http://c2.com/cgi-bin/wiki?WikiWikiWeb (WikiWikiWeb)
* http://phpwiki.sourceforge.net/ (PhpWiki)
* http://wikiml.org/ (WikiML)
* http://www.w3.org/TR/xslt (XSLT)
* http://www.oasis-open.org/docbook (DocBook)

!!!By the way, why is it called Relax NG?

Relax stands for "Regular Language description for XML" and of course, it's also a joke from its author, Murata Makoto who used to advertise his language as: "Tired of complicated specifications? You just RELAX !". Despite its humourous name, Relax has been a very serious candidate as a XML schema language and it has been published as an ISO/IEC Technical Report in 2001 under the title: "ISO/IEC DTR 22250-1, Document Description and Processing Languages -- Regular Language Description for XML (RELAX) --  Part 1: RELAX Core".

Relax has then been merged with TREX (Tree Regular Expressions for XML), another XML schema language proposed by James Clark in 2001 under the name Relax NG (NG standing for "New Generation") the wish of both Murata Makoto and James Clark being that users of Relax and TREX gradually migrate to Relax NG.
