Powered by SmartDoc

The xsd.policy option

The xsd.policy option specifies a modeling policy to generate an XML Schema schema.

parameter

The xsd.policy option takes one of the following values as a parameter:

auto
Relaxer decides the policy.
element
an element-oriented modeling policy.
type
a type-oriented modeling policy.

The default configuration is auto.

Artifacts

The xsd.policy option is reflected to the contents of the XML Schema schema.

Example

List 29.3.3.1[xsdRngPolicy.rng] is an XML Schema schema.

xsdRngPolicy.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>

The auto policy

Execution of Relaxer using the xsd.policy option with a parameter 'auto' is as follows:

$ relaxer -xsd -xsd.policy:auto xsdPolicy.rng

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

The artifact of the XSD generator is shown in List 29.3.3.1.1[xsdRngPolicy.xsd].

xsdRngPolicy.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>

The element policy

Execution of Relaxer using the xsd.policy option with a parameter 'element' is as follows:

$ relaxer -xsd -xsd.policy:element xsdPolicy.rng

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

The artifact of the XSD generator is shown in List 29.3.3.2.1[xsdRngPolicy.xsd].

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

The type policy

Execution of Relaxer using the xsd.policy option with a parameter 'type' is as follows:

$ relaxer -xsd -xsd.policy:type xsdPolicy.rng

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

The artifact of the XSD generator is shown in List 29.3.3.3.1[xsdRngPolicy.xsd].

xsdRngPolicy.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>