Powered by SmartDoc

The xsd option

The xsd option enables Relaxer to generate an XML Schema schema instance from a resource specified by a parameter.

parameter

The xsd option takes no parameters. Specifying the xsd option means that you want to use the XSD generator.

Artifacts

The xsd option generates an XML Schema schema instance from the resource specified by a parameter.

Example1

List 29.2.3.1[xsdRng.rng] is a RELAX NG schema.

xsdRng.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 Relaxer with the xsd option is as follows:

$ relaxer -xsd xsdRng.rng

As a result of this command, Relaxer generates one file:

The artifact of the XSD generator is shown in List 29.2.3.2[xsdRng.xsd].

xsdRng.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="account" type="account"/>
  <xsd:complexType name="account">
    <xsd:sequence>
      <xsd:element name="balance" type="xsd:int"/>
      <xsd:element name="owner" type="xsd:token"/>
<xsd:element maxOccurs="1" minOccurs="0" name="address" type="address"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="phone" \
    type="phone"/>
    </xsd:sequence>
    <xsd:attribute name="accountNo" type="xsd:token"/>
  </xsd:complexType>
  <xsd:complexType name="address">
    <xsd:simpleContent>
      <xsd:extension base="xsd:string">
        <xsd:attribute name="zip" type="xsd:token"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
  <xsd:complexType name="phone">
    <xsd:simpleContent>
      <xsd:extension base="xsd:token">
        <xsd:attribute name="area" type="xsd:token"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
</xsd:schema>

Example2

List 29.2.4.1[xsdXml.xml] is a sample XML document.

xsdXml.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 xsd option is as follows:

$ relaxer -xsd xsdXml.xml

As a result of this command, Relaxer generates one file:

The artifact of the XSD generator is shown in List 29.2.4.2[xsdXml.xsd].

xsdXml.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="account" type="account"/>
  <xsd:complexType name="account">
    <xsd:sequence>
      <xsd:element name="balance" type="xsd:int"/>
      <xsd:element name="owner" type="xsd:token"/>
      <xsd:element name="address" type="address"/>
<xsd:element maxOccurs="unbounded" minOccurs="1" name="phone" \
    type="phone"/>
    </xsd:sequence>
    <xsd:attribute name="accountNo" type="xsd:int"/>
  </xsd:complexType>
  <xsd:complexType name="address">
    <xsd:simpleContent>
      <xsd:extension base="xsd:token">
        <xsd:attribute name="zip" type="xsd:int"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
  <xsd:complexType name="phone">
    <xsd:simpleContent>
      <xsd:extension base="xsd:token">
        <xsd:attribute name="area" type="xsd:int"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
</xsd:schema>