The xs:unsignedInt is still providing xsd validation (so someone cannot unparse a value of "a"). If you wanted to take full advantage of this, you need a more specific xsd type in a maxValue set. Normally Daffodil does not pay attention to xsd restrictions during parse/unparse (although it can optionally do xsd validation before/after a parse/unparse). If you want to take avantage of xsd restrictions during parse/unparse, you can use the dfdl:checkConstraints() function inside of an assert annotation.
Note that setting a max value of 99999 and adding an assert is not quite the same thing using lengthPattern. Using maxValue+assert would fail to parse the input "123456". Using dfdl:lengthPattern would parse "12345" and leave "6" in the dataStream for the next element to parse. Depending on your format, one of these behaviours might be preferable. Often, what works best is to parse all of "123456", then, after parsing is complete, fail the resulting infoset using standard XSD validation. This would be done with a standard xsd restriction (and no dfdl assertions) and lengthKind=delimited and parsing with validation on (or using an external validator). This allows for parsing syntactically valid data, which may make debugging semantically invalid data easier. This is not an option succesfully parsing requires backtracking when the integer is too big. ________________________________ From: Costello, Roger L. <[email protected]> Sent: Wednesday, June 19, 2019 12:51:12 PM To: [email protected] Subject: Re: How to declare an element of type xs:unsignedInt, restricted to one to five digit characters? The disadvantage that I can see with that solution is the xs:unsignedInt is doing essentially nothing – it may as well be xs:string. The pattern is doing all the constraining. Do you agree? Thanks Brandon. /Roger From: Sloane, Brandon <[email protected]> Sent: Wednesday, June 19, 2019 12:13 PM To: [email protected] Subject: [EXT] Re: How to declare an element of type xs:unsignedInt, restricted to one to five digit characters? Assuming your input is plaintext, you could use the dfdl:lengthPattern attribute: <xs:element name="value" type="xs:unsignedInt" dfdl:lengthKind="pattern" dfdl:lengthPattern="[0-9]{1,5}" /> You could also use lengthKind="delimited" and add an assertion (and/or xsd restriction) on the value. ________________________________ From: Costello, Roger L. <[email protected]<mailto:[email protected]>> Sent: Wednesday, June 19, 2019 9:30:11 AM To: [email protected]<mailto:[email protected]> Subject: How to declare an element of type xs:unsignedInt, restricted to one to five digit characters? Hello DFDL community, The below DFDL schema says that the input must contain a string that represents an unsignedInt and the string must not contain more than five digit characters. Eek! That's not correct. The below DFDL schema says that the input must contain a string that represents an unsignedInt and the string must contain *exactly* five digit characters. Is there a way to write the DFDL schema to specify that the input must contain a string that represents an unsignedInt and the string must contain *one to five* digit characters? That is, how to specify that the input could be any of these strings: "0", "1", ..., "99999" <xs:element name="input"> <xs:complexType> <xs:sequence> <xs:element name="value" type="xs:unsignedInt" dfdl:lengthKind="explicit" dfdl:length="5" dfdl:lengthUnits="characters" /> </xs:sequence> </xs:complexType> </xs:element>
