Organizing the DFDL model

The third stage of an approach to modeling data by using DFDL involves organizing the DFDL model so that common DFDL property values are declared in a single place and act as defaults for all the components in the schema.

Before you begin

Before you start:

Follow the guidance in Understanding the logical structure and Configuring the DFDL annotations.

About this task

All DFDL schemas that are created by the IBM® DFDL wizards and importers follow the practices as described here.

Procedure

  • Set up common DFDL property defaults by using a dfdl:format annotation at the top level of the schema.

    A DFDL schema can be set up so that DFDL properties that are common to multiple schema components need be declared only once, by using a dfdl:format annotation at the top level of the schema itself to declare properties. These properties effectively act as defaults for all components in the schema. (DFDL has no built-in property defaults.)

  • A further refinement is to place those properties in a separate DFDL schema for reuse in other related DFDL schemas.

    Create a separate DFDL schema to contain these common DFDL properties, and place them inside a dfdl:defineFormat annotation. This schema is then included into the main DFDL schema through an XSD include or import. The dfdl:format annotation at the top level of the main schema instead uses dfdl:ref to refer to the dfdl:defineFormat. Much like a macro expansion, properties are pulled from the dfdl:defineFormat onto the dfdl:format, where they then act as defaults for all components in the schema in the way described above. In this way, common DFDL properties can be shared across multiple related DFDL schemas.

    Figure 1. defaults.xsd
    
    <xs:schema>
      <xs:annotation>
        <xs:appinfo source="http://www.ogf.org/dfdl/" >
          <dfdl:defineFormat name="myDefaults" >
             <!- Declare common DFDL property values -->
             <dfdl:format encoding="ASCII" representation="text" ... />
          </dfdl:defineFormat>
        </xs:appinfo>
      </xs:annotation>
    </xs:schema>    
    
    
  • Now, you need only to set a handful of properties directly on each object to complete configuration.
    1. Figure 2. employees.xsd
      <xs:schema>
        <xs:include schemaLocation="defaults.xsd" />
      
        <xs:annotation>
          <xs:appinfo source="http://www.ogf.org/dfdl/" >
            <!- Apply common DFDL property values as defaults -->
            <dfdl:format ref="myDefaults" />
          </xs:appinfo>
        </xs:annotation>
      
        <!- Add only DFDL properties that differ from the defaults -->
        <xs:element name="employeeRecord" maxOccurs="unbounded" dfdl:lengthKind="implicit"  
                                          dfdl:initiator="{{" dfdl:terminator="}%CR;%LF;" >
          <xs:complexType>
               ...
          </xs:complexType>
        </xs:element>
      
        ...
      
      </xs:schema>