Powered by SmartDoc

rng option

The rng option enables Relaxer to generate a RELAX NG schema instance from a resource specified by a parameter.

parameter

The rng option takes no parameters. Specifying the rng option indicates that you want to use the RELAX NG generator.

Artifacts

The rng option generates a RELAX NG schema instance from the resource specified by a parameter.

Example

You can get a RELAX NG schema from a RELAX Core schema using Relaxer.

List 23.2.3.1[rngRxm.rxm] is a sample RELAX Core document.

rngRxm.rxm
<?xml version="1.0" encoding="UTF-8" ?>
<module xmlns="http://www.xml.gr.jp/xmlns/relaxCore"
        relaxCoreVersion="1.0"
        targetNamespace="">
  <interface>
    <export label="account"/>
  </interface>
  <elementRule label="account">
    <tag name="account">
      <attribute name="accountNo" required="true" type="token"/>
    </tag>
    <sequence>
      <element name="balance" type="int"/>
      <element name="owner" type="token"/>
      <ref label="address" occurs="?"/>
      <ref label="phone" occurs="*"/>
    </sequence>
  </elementRule>
  <elementRule label="address" type="string">
    <tag name="address">
      <attribute name="zip" required="true" type="token"/>
    </tag>
  </elementRule>
  <elementRule label="phone" type="token">
    <tag name="phone">
      <attribute name="area" required="true" type="token"/>
    </tag>
  </elementRule>
</module>

Execution of Relaxer with the rng option is as follows:

$ relaxer -rng rngRxm.rxm

As a result, Relaxer generates 1 file:

The artifact of the RELAX NG generator (a file) is shown in List 23.2.3.2[rngRxm.rng].

rngRxm.rng
<?xml version="1.0" encoding="UTF-8" ?>
<grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" \
    xmlns="http://relaxng.org/ns/structure/1.0" \
    xmlns:java="http://www.relaxer.org/xmlns/relaxer/java" \
    xmlns:jdbc="http://www.relaxer.org/xmlns/relaxer/jdbc" \
    xmlns:relaxer="http://www.relaxer.org/xmlns/relaxer">
  <start>
    <ref name="account"/>
  </start>
  <define name="account">
    <element name="account">
      <attribute name="accountNo">
        <data type="token"/>
      </attribute>
      <element name="balance">
        <data type="int"/>
      </element>
      <element name="owner">
        <data type="token"/>
      </element>
      <optional>
        <ref name="address"/>
      </optional>
      <zeroOrMore>
        <ref name="phone"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="address">
    <element name="address">
      <attribute name="zip">
        <data type="token"/>
      </attribute>
      <text/>
    </element>
  </define>
  <define name="phone">
    <element name="phone">
      <attribute name="area">
        <data type="token"/>
      </attribute>
      <data type="token"/>
    </element>
  </define>
</grammar>

Example2

You can get a RELAX NG schema from an XML document using Relaxer.

List 23.2.4.1[rngXml.xml] is a sample XML document.

rngXml.xml
<account accountNo="12345">
  <balance>102030</balance>
  <owner>XML Taro</owner>
  <address zip="213">Yokohama</address>
  <phone area="123">456-7890</phone>
  <phone area="090">123-4567</phone>
</account>

Execution of Relaxer with the rng option is as follows:

$ relaxer -rng rngXml.xml

As a result, Relaxer generates 1 file:

The artifact of the RELAX NG generator (a file) is shown in List 23.2.4.2[rngXml.rng].

rngXml.rng
<?xml version="1.0" encoding="UTF-8" ?>
<grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" \
    xmlns="http://relaxng.org/ns/structure/1.0" \
    xmlns:java="http://www.relaxer.org/xmlns/relaxer/java" \
    xmlns:jdbc="http://www.relaxer.org/xmlns/relaxer/jdbc" \
    xmlns:relaxer="http://www.relaxer.org/xmlns/relaxer">
  <start>
    <ref name="account"/>
  </start>
  <define name="account">
    <element name="account">
      <attribute name="accountNo">
        <data type="int"/>
      </attribute>
      <element name="balance">
        <data type="int"/>
      </element>
      <element name="owner">
        <data type="token"/>
      </element>
      <ref name="address"/>
      <oneOrMore>
        <ref name="phone"/>
      </oneOrMore>
    </element>
  </define>
  <define name="address">
    <element name="address">
      <attribute name="zip">
        <data type="int"/>
      </attribute>
      <data type="token"/>
    </element>
  </define>
  <define name="phone">
    <element name="phone">
      <attribute name="area">
        <data type="int"/>
      </attribute>
      <data type="token"/>
    </element>
  </define>
</grammar>