Hi Folks,
Please let me know of anything that is unclear. /Roger
--------------------------------------------------------------------------------------
5. Fixed length, not nillable, not composite, no choice
This is an easy one.
We will create a DFDL schema for a field containing a Social Security Number. I
named the field "SSN."
Here is a sample value:
123-45-6789
The field has a fixed length of 11.
Field Requirements:
>> Fixed length (11)
>> Not nillable
>> No choice
>> Not composite, i.e., single atomic value
Add to the field these two DFDL properties:
dfdl:lengthKind="explicit"
dfdl:length="__"
Here's the DFDL schema with the DFDL properties added (shown in yellow):
<xs:element name="SSN"
dfdl:lengthKind="explicit"
dfdl:length="11">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{3}-[0-9]{2}-[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
That's it!
One last (important) point: When parsing input with Daffodil use the -V limited
option. The option instructs Daffodil to validate the field against the XSD
pattern facet. With this erroneous input value:
xxx-45-6789
Daffodil gives this very helpful error message on parsing:
[error] Validation Error: SSN failed facet checks due to: facet pattern(s):
[0-9]{3}-[0-9]{2}-[0-9]{4}
If you don't use the -V limited option, then Daffodil won't validate the parts
against the XSD facets. Consequently, Daffodil will not report any errors with
the above erroneous input. Why? Because if we ignore the facets in this element
declaration:
<xs:element name="SSN"
dfdl:lengthKind="explicit"
dfdl:length="11">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{3}-[0-9]{2}-[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
then it is simply saying that the input is any text of length 11, and
"xxx-45-6789" certainly fits that specification.