[DFDL-WG] proposal: add fn:error function and dfdl:hex function to DFDL

Mike Beckerle mbeckerle.dfdl at gmail.com
Thu Jun 20 13:09:44 EDT 2013


Proposed: add fn:error function and add dfdl:hex function.

DFDL only needs one of the several variations of fn:error

fn:error($error as xs:QName?, $description as xs:string) as none

dfdl:hex($num as xs:integer) as string

The dfdl:hex function inverts the behavior of the dfdl:byte, and related
functions (currently also proposed) which take a string specification of a
hex value. The argument to dfdl:hex can be a long, unsignedLong, or any
subtype thereof. The number of hex digits in the resulting string is a
function of the input type. If byte or unsigned byte, exactly 2 hex digits
are produced, for short and unsignedShort, 4 hex digits, and so on. The
resulting value contains a prefix 'x' character as its first character. So:

dfdl:short(dfdl:hex(xs:short(208))) eq xs:short(208)

is true, and a corresponding tautology holds for all the other DFDL
functions that construct integers from hexadecimal, if you replace the 208
above with a value in range for the corresponding numeric type.

Example:

This allows a meaningful error message that includes the offending parts of
data.

fn:error(ex:magic_number, fn:concat("The magic number: 0", dfdl:hex(.), "
was not 0xA1B2C3D4 (for bigEndian) or 0xD4C3B2A1 (for littleEndian)."))

The $error argument (of type QName) is used in an implementation-dependent
manner to provide the context of the error. So for example, if namespace
prefix 'ex' is bound to 'http://example.com' then the above call might
produce:

"Error: {http://example.com}magic_number - The magic number: 0xFEFF0000 was
not 0xA1B2C3D4 (for bigEndian) or 0xD4C3B2A1 (for littleEndian)."

Only the part of the above string after the hyphen is standardized. The
hyphen and part before the hyphen is implementation dependent.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ogf.org/pipermail/dfdl-wg/attachments/20130620/86b851f9/attachment.html>


More information about the dfdl-wg mailing list