Versions Compared

Key

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

...

Code Block
type t2[B] = {
  repType = t1[A]
  inputTypeCalc : A -> B
  outputTypeCalc : B -> A

  parse : bin -> B
  parse :=  inputTypeCalc ∘ t1.parse

  unparse : B -> bin
  unparse := t2.unparse ∘ outputTypeCalc
}

 



As you can see, we can describe a new type, t2, which translates between binary and logical type B, by using the existing type t1[A], and a pair of functions to translate between A and B.

...

Code Block
<xs:choice dfdlx:choiceBranckKeyKind=”byType” dfdlx:choiceDispathKeyKind=”byType”>
  <xs:element name=”fruit” type=”tns:fruitEnumType”/>
  <xs:element name=”localFruit” type=”tns:fruitLocalType”/>
  <xs:element name=”disused” type=”tns:fruitDisusedType”/>
</xs:choice>

...


We explicitly forbid choiceBranchKeyKind="explicit" to co-occur with choiceDispatchKeyKind="byType"

This is to avoid dealing with potentially ambiguous unparse situations that could occur with schemas like the following:

Code Block
<xs:simpleType name="one_or_two" dfdl:repType="tns:uint8">
  <xs:restriction base="xs:string">
    <xs:enumeration value="1 or 2" dfdl:repValues="1 2"/>
  </xs:restriction>
</xs:simpleType>

<xs:choice dfdl:choiceBranchKeyKind="explicit" dfdl:choiceDispatchKeyKind="byType">
  <xs:element name="one" type="tns:one_or_two" dfdl:choiceBranchKey="1"/>
  <xs:element name="two" type="tns:one_or_two" dfdl:choiceBranchKey="2"/>
</xs:choice>

In this case, the binary input 02 would parse to <two>1 or 2</two>. However, it is ambiguous if we should unparse this according to the canonical value of the type (1), or the canonical branchKey (2).


Using with explicit raw elements

It may be desirable to include both the raw and logical values in the infosets. Traditionally, this It may be desirable to include both the raw and logical values in the infosets. Traditionally, this usecase has been accomplished using inputValueCalc and outputValueCalc annotations. This remains the case here. To support this usecase, we expose the inputTypeCalc/outputTypeCalc functions to the DFDL expression language:

...

Code Block
<xs:sequence >
  <xs:element name="raw" type="tns:fruitRepType" dfdlx:outputValueCalc=”dfdlx:outputTypeCalcInt(tns:fruitEnumType, ../fruit)”/>
  <xs:element name=”fruit” type=”tns:fruitEnumType” dfdlx:inputValueCalc=”dfdlx:inputTypeCalcString(tns:fruitRepType, ../raw)”/>
</xs:sequence>

...



A more complicated example would be using a raw element with a choice of logical elements:

...

  • dfdlx:repType
    • Applies to xs:simpleType
    • Defines the representation type associated with the annotated type.
    • On parse, the DFDL processor first parses according to the repType, then applies any conversion specified by the annotated type.
    • On unparse, the DFDL processor first applies the conversion specified by the annotated type, then the unparse behavior specified by the repType
  • dfdlx:choiceBranchKeyKind
    • Applies to xs:choice
    • Values: byType, explicit, speculative, implicit
    • byType
      • Each choice option must be a simple element
      • All choice options must have a type with a common repType
      • The valueSets of all options must be mutually disjoint
      • The choice dispatch will behave as if the choiceBranchKeys specified by an option are the valueSet of the options type.
    • Explicit
      • Each choice option must directly specify a choiceBranchKey. These values will be used for direct dispatch
      • Requires choiceDispatchKeyKind=explicit as well
    • Speculative
      • Direct dispatch will not be used. Choice options will be parsed speculatively, and the first non-failing case will be used
      • Requires choiceDispatchKeyKind=speculative
    • Implicit
      • Current behavior
      • If choice options provide explicit choiceBranchKeys, then behave as if we were “explicit”
      • Otherwise, behave as if we were “speculative”
  • dfdlx:choiceDispatchKeyKind
    • Applies to xs:choice
    • Values: byType, explicit, speculative, implicit
    • byType
      • Each choice option must be a simple element
      • All choice options must have a type with a common repType
      • First, parse according to the common repType without consuming any input
      • Then, use the resulting value as the choiceDispatchKey
    • Explicit
      • Gets the choiceDispatchKey from the dfdlx:choiceDispatchKey annotation
    • Speculative
      • Direct dispatch will not be used. Choice options will be parsed speculatively, and the first non-failing case will be used
      • Requires choiceBranchKeyKind=speculative
    • Implicit
      • Current behavior
      • If dfdlx:choiceDispatchKey is present, them behave as if we were explicit
      • Otherwise, behave as if we were speculative

...


  • dfdlx:inputTypeCalc
    • Applies to xs:simpleType
    • Requires dfdlx:repType to also be present
    • Is a DFDL expression
    • On parse, first parse according to the repType, then populate the value of this element to the result of evaluating the dfdlx:inputTypeCalc expression
    • The value of the repType may be accessed by the expression through the dfdlx:repTypeValue() function
  • dfdlx:ouputTypeCalc
    • Applies to xs:simpleType
    • Requires dfdlx:repType to also be present
    • Is a DFDL expression
    • On unparse, first evaluate this expression, then unparse according to the repType as if the logical value were the result of evaluating this expression
    • The original logical value of this type may be accessed by the expression through the dfdlx:logicalTypeValue() function
  • dfdlx:repValues
    • Applies to xs:enumeration and xs:simpleType
    • A space separated list of values
    • Values must be of a type consistend with repType
    • When applied to xs:enumeration:
      • Defines a KeySet-Value transform, and associates the annotated enumeration value with the listed keys
      • Adds the listed values to the repValue set of the parent simpleType
    • When Applied to xs:simpleType
      • Adds the listed keys to the repValue set of the parent
      • This set will be used by xs:choice when choiceBranchKeyKind=byType
  • dfdlx:repValueRanges
    • Applies to xs:enumeration and xs:simpleType
    • Requires dfdlx:repType to be present and refer to an integer type
    • A space separated list of integers defining ranges of integers
    • Takes the form “min1 max1 min2 max2 … minN maxN”
    • Represents the set of integers described by the union of the intervals [mink, maxK]
    • Behaves as if all members of this set were included in the dfdlx:repValues annotation

...