Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Let's look at an example of two interacting data layer transforms. Below we have an example that is contrived, but has some resemblance to MIME formats.  It parses a textual format where all lines that are too long are folded. WIthin it there are delimiter strings and layer boundaryMark strings (same string actually), computed from the data. The actual data 'payload' here is in the child element named 'body', and it is just a string, but it is base64 encoded. More typically, base64 would be used for binary data, or for text with complex character set encodings. This example is just using a string for exposition purposes.

Code Block
languagexml
<annotation><appinfo source="http://www.ogf.org/dfdl/">
 <dfdl:defineFormat name="base64">
      <dfdl:format ref="ex:general" layerTransform="base64_MIME" layerLengthKind="boundaryMark" layerLengthUnits="bytes"
        layerEncoding="iso-8859-1" />
 </dfdl:defineFormat>
 <dfdl:defineFormat name="folded">
      <dfdl:format ref="ex:general" layerTransform="lineFolded_IMF" layerLengthKind="implicit" layerLengthUnits="bytes"
        layerEncoding="iso-8859-1" />
 </dfdl:defineFormat>
</appinfo></annnotation>

    <xs:element name="root" dfdl:lengthKind="implicit">
      <xs:complexType>
        <xs:sequence dfdl:ref="folded"> <!-- From here, everything is line-folded -->
          <xs:sequence>
            <xs:element name="marker" type="xs:string"
              dfdl:initiator="boundary=" dfdl:terminator="%CR;%LF;" />
            <xs:element name="contents" dfdl:lengthKind="implicit" 
              dfdl:initiator="{ fn:concat('--', ../marker, '%CR;%LF;') }">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="comment" type="xs:string" 
                    dfdl:initiator="Comment:%SP;" dfdl:terminator="%CR;%LF;" />
                  <xs:element name="contentTransferEncoding"  type="xs:string"
                    dfdl:initiator="Content-Transfer-Encoding:%SP;"
                    dfdl:terminator="%CR;%LF;" />
                  <xs:element name="body" dfdl:lengthKind="implicit" dfdl:initiator="%CR;%LF;">
                    <xs:complexType>
                      <xs:choice dfdl:choiceDispatchKey="{ ../contentTransferEncoding }">
                        <xs:sequence dfdl:choiceBranchKey="base64">
                          <xs:sequence dfdl:ref="tns:base64"
                            dfdl:layerBoundaryMark="{ 
                              fn:concat(dfdl:decodeDFDLEntities('%CR;%LF;'),'--', ../../marker, '--')
                             }"> <!-- base64_MIME encoding for this sequence -->
                            <xs:element name="value" type="xs:string" />
                          </xs:sequence> <!-- END base64_MIME encoding --> 
                        </xs:sequence>
                        <!--
                           This is where other choice branches than base64 would go. 
                         -->
                      </xs:choice>
   
Code Block
languagexml
<dfdl:defineFormat name="foldedLines">
  <dfdl:format layerTransform="lineFolded_IMF" dfdl:layerLengthKind="boundaryMark"/>
</dfdl:defineFormat>

<dfdl:defineFormat name="base64">
  <dfdl:format layerTransform="base64_MIME" layerEncoding="us-ascii" layerLengthKind="boundaryMark" layerBoundaryMark='{ ./marker }'/>
  <!-- note expression above is ./marker, not ../marker -->
</dfdl:defineFormat>

 <xs:sequence dfdl:ref="tns:foldedLines">
   <xs:sequence>
     ...
     ... presumably everything here is textual, and utf-8. FoldedLines only applies sensibly to text.
     ...
     <xs:element name="marker" type="xs:string" .../>
     <xs:sequence dfdl:ref="tns:base64">
        <xs:sequence>
          ...
          ... everything here is parsed against the bytes obtained from base64 decoding
 </xs:complexType>
              ... which is itself decoding the output of the foldedLines transform
</xs:element> <!-- END element body --> 
             ... above. Base64 requires only us-ascii, which is a subset of utf-8.
 </xs:sequence>
              </xs:complexType>
    ...
        </xs:sequence><element> <!-- endEND base64element datacontents -->
        <   </xs:sequence><!-- end base64 sequence e.g., framing, aligning -->
sequence>
        </xs:sequence><sequence> <!-- endEND ofline foldedLinesfolding data-->
      </xs:sequence><!-- end foldedLines sequence e.g., framing, aligning -->complexType>
    </xs:element>

VCalendar Example

Consider this VCALENDAR Data:

...