2. Specifying which RELAX NG schema to use for validating a document
Prev |  | Next

## 2. Specifying which RELAX NG schema to use for validating a document

This section is just a primer. The reference documentation about this topic is really XMLmind XML Editor - Configuration and Deployment.

### 2.1. The `relaxng` configuration element

A document type declaration (`<!DOCTYPE>`) can be used to associate a DTD to a document. Attributes `xsi:schemaLocation`/`xsi:noNamespaceSchemaLocation` can be used to associate W3C XML Schemas to a document. But there is no standard way to associate a RELAX NG schema to a document. Therefore this association must be made using an external specification such as the Namespace Routing Language (NRL).

In the case of XMLmind XML Editor, this external specification is simply a configuration element called `relaxng`.

XHTML example:

    <configuration name="XHTML Strict [RELAX NG]"
      xmlns:html="http://www.w3.org/1999/xhtml"
      xmlns="http://www.xmlmind.com/xmleditor/schema/configuration">
      <include location="xxe-config:schema/ns_xhtml.incl" />

      <detect>
        <rootElementNamespace>http://www.w3.org/1999/xhtml</rootElementNamespace>
      </detect>

      <relaxng name="http://www.w3.org/1999/xhtml"
               location="xxe-config:common/rng/xhtml1/xhtml-strict.rng" />

      <preserveSpace elements="html:pre html:style html:script" />

      <css name="XHTML" location="xhtml_rng.css" />
      <template name="Page" location="page.html" />
    </configuration>

| The `name` attribute, which is similar to the public ID of a DTD, is absolutely not required. However, if it is absent, the corresponding RELAX NG schema cannot be cached by XXE.
| Unlike the DTD, `xhtml-strict.rng` does not specify a `preserve` default value for attribute `xml:space` of elements such as `pre`. Therefore, the `preserveSpace` configuration element must be used to specify whitespace-preserving elements.

### 2.2. The `<?xxe-relaxng-schema>` processing instruction

This processing instruction is a non standard, proprietary, way to associate a document to a RELAX NG schema. Its use should be restricted to testing and other quick and dirty experiments.

DocBook example:

    <?xml version="1.0" encoding="UTF-8" ?>
    <?xxe-relaxng-schema name="-//OASIS//RELAX NG DocBook V4.3//EN"
      location="http://www.docbook.org/rng/4.3/docbook.rnc"
      compactSyntax="true" encoding="US-ASCII" ?>

    <!DOCTYPE article [

    <!ENTITY % sgml.features "IGNORE">
    <!ENTITY % xml.features "INCLUDE">

    <!ENTITY euro "&#x20AC;">

    <!ENTITY % dbcent PUBLIC
    "-//OASIS//ENTITIES DocBook Character Entities V4.3//EN"
    "http://www.oasis-open.org/docbook/xml/4.3/dbcentx.mod">
    %dbcent;

    ]>

    <article>
      <title></title>
      <section>
        <title></title>
        <para></para>
      </section>
    </article>

| The `<?xxe-relaxng-schema>` processing instruction has pseudo-attributes identical to the attributes of the `relaxng` configuration element.
| Using a RELAX NG schema should not prevent you from specifying a document type declaration for character entities.

### 2.3. Sample XXE configurations using RELAX NG schemas

The examples used in this section come from two unbundled XXE configurations:

`docbook5_config`

  Allows to create and edit DocBook V5.0beta documents conforming to the RELAX NG schema coming from DocBook.org.

  ### Caution

  This configuration should be considered as a work in progress. If you just want to author DocBook documents, do not use this RELAX NG-based configuration. Rather use the bundled, DTD-based, configuration which is much more mature.

docbook5xi_config

  Same as `docbook5_config`, except that this configuration uses a variant of the grammar (`docbookxi.rng`) which allows most elements to contain `xi:include` elements.

  This configuration is useful for authors who do not want XInclude elements to be transcluded, as it is the case with `docbook5_config`.

  You cannot install both `docbook5_config` and `docbook5xi_config`.

`xhtml_rng_config`

  Allows to create and edit XHTML 1.0 documents conforming to the modular RELAX NG schema written by James Clark.

  ### Caution

  This configuration should be considered as a work in progress. If you just want to author XHTML documents, do not use this RELAX NG-based configuration. Rather use the bundled, DTD-based, configuration which is much more mature.

In order to use these configurations, you need to download and install them using Options|Install Add-ons. Note that these two RELAX NG-based configurations do not conflict with the DTD-based XHTML and DocBook configurations which are bundled with XXE.

Prev |  | Next
1. Implementation of RELAX NG in XMLmind XML Editor | Home | 3. XMLmind XML Editor-friendly content models