Powered by SmartDoc

default

The extention syntax attribute default specifies a default value for a property.

Both RELAX Core and RELAX NG do not hava a functionality to specify a default value for a data property. This is reasonable because an XML document instance is isolated from its schema definition. This is because a schema definition is a specification and a default value is merely information to be used by the implementation.

Relaxer is a implementation technology. Therefore the extension syntax for default value is supported.

Target

A target for the default is data.

Parameters

The default attribute takes a concrete value to be a default value for the property.

Artifact

The default value of the property is the value specified by the default attribute.

Example

List 8.2.4.1[grammarDefault.rng] is a sample schema for the default attribute. In a grammar element, a namespace prefix java is declared as a namespace http://www.relaxer.org/xmlns/relaxer/java.

There are two places the default attribute is used. One is a data element in an element element named balance. Another one is a data element in an element element named owner.

grammarDefault.rng
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         xmlns:java="http://www.relaxer.org/xmlns/relaxer/java"
         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" java:default="-1">
        <data type="int"/>
      </element>
      <element name="owner" java:default="Unknown">
        <data type="token"/>
      </element>
      <ref name="address"/>
      <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>