home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeXML SchemaSearch this book

A.7. RELAX NG

Its editors (James Clark and Murata Makoto) define RELAX NG as "the next generation schema language for XML: clean, simple, and powerful." RELAX NG appears to be closer to a description of the instance documents in ordinary English as well as simpler than the W3C XML Schema, to which it might become a serious alternative. Many constraints, especially those on the fringe of nondeterministic models, can be expressed by RELAX NG and not by the W3C XML Schema. Some combinations in document structures forbidden by the W3C XML Schema can be described by RELAX NG. Even though RELAX NG seems to be technically superior to the W3C XML Schema, support by software vendors and XML developers is uncertain given that W3C XML Schema is a W3C Recommendation. Table A-3 provides the fact sheet for RELAX NG.

Table A-3. RELAX NG fact sheet

Author:

OASIS and possibly ISO/DSDL.

Status:

OASIS RELAX NG Committee Specification.

Location:

http://relaxng.org.

Type:

Grammar-based.

PSVI:

No.

Structures:

Yes.

Datatypes:

No, but a modular mechanism has been defined to plug in datatype systems (W3C XML Schema Part 2 and others if needed).

Integrity:

No.

Rules:

No.

Vendor support:

To be seen.

Miscellaneous:

Result of the merge between RELAX and TREX, might become an ISO IS. Strong mathematical grounding. Alternate non-XML syntax proposed by James Clark.

A.7.1. Example

<grammar
  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
  xmlns="http://relaxng.org/ns/structure/1.0">
  <start>
    <ref name="library"/>
  </start>
  <define name="library">
    <element name="library">
      <oneOrMore>
        <ref name="book"/>
      </oneOrMore>
      <zeroOrMore>
        <ref name="author"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="character"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="author">
    <element name="author">
      <attribute name="id">
        <data type="ID"/>
      </attribute>
      <element name="name">
        <text/>
      </element>
      <element name="nickName">
        <text/>
      </element>
      <element name="born">
        <text/>
      </element>
      <element name="dead">
        <text/>
      </element>
    </element>
  </define>
  <define name="book">
    <element name="book">
      <ref name="id-attribute"/>
      <ref name="isbn"/>
      <ref name="title"/>
      <zeroOrMore>
        <element name="author-ref">
          <attribute name="id">
            <data type="IDREF"/>
          </attribute>
          <empty/>
        </element>
      </zeroOrMore>
      <zeroOrMore>
        <element name="character-ref">
          <attribute name="id">
            <data type="IDREF"/>
          </attribute>
          <empty/>
        </element>
      </zeroOrMore>
    </element>
  </define>
  <define name="id-attribute">
    <attribute name="id">
      <data type="ID"/>
    </attribute>
  </define>
  <define name="character">
    <element name="character">
      <ref name="id-attribute"/>
      <ref name="name"/>
      <ref name="since"/>
      <ref name="qualification"/>
    </element>
  </define>
  <define name="isbn">
    <element name="isbn">
      <text/>
    </element>
  </define>
  <define name="name">
    <element name="name">
      <text/>
    </element>
  </define>
  <define name="nickName">
    <element name="nickName">
      <text/>
    </element>
  </define>
  <define name="qualification">
    <element name="qualification">
      <text/>
    </element>
  </define>
  <define name="since">
    <element name="since">
      <data type="date"/>
    </element>
  </define>
  <define name="title">
    <element name="title">
      <text/>
    </element>
  </define>
</grammar>


Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.