Namespaces, Building Blocks, and Chameleon Design

RELAX not only lets you create building blocks for inclusion into schemas, it lets you create generic building blocks that take on a namespace you specify when including those blocks into your own schemas. These generic blocks, called chameleon schemas , are designed so that they can take on the namespace of their surrounding environment.

Reexamining XHTML 2.0

Chapter 10 explored the schemas for XHTML 2.0. At the time, I told you not to worry about the namespace declarations because they hadn’t been introduced yet. It’s time to take a closer look at XHTML’s namespace usage. XHTML’s namespace declarations in the top level schema, the driver schema, are present only in the grammar element:

 <?xml version="1.0" encoding="UTF-8"?>
 <grammar ns="http://www.w3.org/2002/06/xhtml2"
         xmlns="http://relaxng.org/ns/structure/1.0"
         xmlns:x="http://www.w3.org/1999/xhtml">

  <x:h1>RELAX NG schema for XHTML 2.0</x:h1>
  .../...
    <x:h3>Structure Module</x:h3>
    <include href="xhtml-struct-2.rng"/>
   .../...
 </grammar>

What does this snippet demonstrate?

xmlns="http://relaxng.org/ns/structure/1.0"

Means that the default namespace of the schema as a XML document is http://relaxng.org/ns/structure/1.0. Translated, it means that elements without prefix in the schema as a XML document are RELAX NG patterns.

ns="http://www.w3.org/2002/06/xhtml2"

Defines the default namespace for the schema itself: the schema describes elements from the http://www.w3.org/2002/06/xhtml2 ...

Get RELAX NG now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.