Powered by SmartDoc

rxm option

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

parameter

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

Artifacts

The rxm option generates a RELAX Core schema instance from the resource specified by a parameter.

Example1

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

List 25.2.3.1[rxmRng.rng] is a RELAX Core schema.

rxmRng.rng
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <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>

Execution of the relaxer with the rxm options is as follows.

$ relaxer -rxm rxmRng.rng

As a result, Relaxer generates 1 file:

The artifact of the RELAX Core generator is shown in List 25.2.3.2[rxmRng.rxm].

rxmRng.rxm
<?xml version="1.0" encoding="UTF-8" ?>
<module relaxCoreVersion="1.0" targetNamespace="" \
    xmlns="http://www.xml.gr.jp/xmlns/relaxCore">
  <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>

Example2

List 25.2.4.1[rxmXml.xml] is a sample XML document.

rxmXml.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 the relaxer with the rxm options is as follows.

$ relaxer -rxm rxm.xml

As a result, Relaxer generates 1 file:

The artifact of the RELAX Core generator is shown in List 25.2.4.2[rxmXml.rxm].

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