Fandom

File Formats Wiki

RELAX NG

261pages on
this wiki
Add New Page
Talk0 Share
RELAX NG
Blank

Filename extension .rng
Compact RELAX NG
Blank

Filename extension .rnc
File formats category - v  e   edit
Smallwikipedialogo.png Wikipedia has an article related to:

RELAX NG (REgular LAnguage for XML Next Generation) is a schema language for XML, based on Makoto Murata's RELAX and James Clark's TREX. A RELAX NG schema specifies a pattern for the structure and content of an XML document. A RELAX NG schema is itself an XML document; however, RELAX NG also offers a popular compact, non-XML syntax.[1]

Compared to other popular schema languages, RELAX NG is relatively simple. It is defined by a committee specification of the OASIS RELAX NG technical committee, and also by part two of the international standard ISO/IEC 19757: Document Schema Definition Languages.[2][3]

Schema examplesEdit

Suppose we want to define an extremely simple XML markup scheme for a book: a book is defined as a sequence of one or more pages; each page contains text only. A sample XML document instance might be:

<book>
  <page>This is page one.</page>
  <page>This is page two.</page>
</book>

XML syntaxEdit

A RELAX NG schema can be written in a nested structure by defining a root element that contains further element definitions, which may themselves contain embedded definitions. A schema for our book in this style, using the full XML syntax, would be written:

<element name="book" xmlns="http://relaxng.org/ns/structure/1.0">
   <oneOrMore>
      <element name="page">
         <text/>
      </element>
   </oneOrMore>
</element>

Nested structure becomes unwieldy with many sublevels and cannot define recursive elements, so most complex RELAX NG schemas use references to named pattern definitions located separately in the schema. Here, a "flattened schema" defines precisely the same book markup as the previous example:

<grammar xmlns="http://relaxng.org/ns/structure/1.0">
   <start>
      <element name="book">
         <oneOrMore>
            <ref name="page"/>
         </oneOrMore>
      </element>
   </start>
   <define name="page">
      <element name="page">
         <text/>
      </element>
   </define>
</grammar>

Compact syntaxEdit

RELAX NG compact syntax is a non-XML format designed so that it can be unambiguously translated to its XML counterpart, and back again, with one-to-one correspondence in structure and meaning, in much the same way that Simple Outline XML (SOX) relates to XML. It shares many features with the syntax of DTDs. Here is the compact form of the above schema:

element book
{
    element page { text }+
}

With named patterns, this can be flattened to:

start = element book { page+ }
page = element page { text }

A compact RELAX NG parser will treat these two as the same pattern.

Comparison with W3C XML SchemaEdit

Although the RELAX NG specification was developed at roughly the same time as the W3C XML Schema specification, the latter was arguably better known and more widely implemented in both open-source and commercial XML parsers and editors when it became a W3C Recommendation in 2001. Since then, however, RELAX NG support has increasingly found its way into XML software, and its acceptance has been aided by its adoption as a primary schema for popular documentric markup languages.

RELAX NG shares with W3C XML Schema many features that set both apart from traditional DTDs: data typing, regular expression support, namespace support, and the ability to reference complex definitions.

Filename extensionsEdit

By informal convention, RELAX NG schemas in the regular syntax are typically named with the filename extension ".rng". For schemas in the compact syntax, the extension ".rnc" is used.

ReferencesEdit

External linksEdit

This page uses CC-BY-SA content from Wikipedia (authors). Smallwikipedialogo.png

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.