Handling null values

A business message might contain fields that are either empty or have a specific out-of-range value. In these cases, the application that receives the message is expected to treat the field as if it did not have a value. The logical message tree supports this concept by enabling the value of any element to be set to NULL.

Ways to represent a null value

In an XML document, the usual way to represent a null value is to leave the element or attribute empty.

For example, <price></price> or <element price=""/>.

The xsi:nil attribute provides a way to make this representation more explicit: <price=xsi:nil="true"/>

Some business messages use a special value to represent a null value: <price>-999</price>. This style of null representation is supported by the DFDL and MRM parsers.

DFDL parser support for null values

The DFDL parser can detect a null value that is represented by an out-of-range value. The null value must be specified in the DFDL schema, and can be the same or different for each element. In DFDL, a null value is called a nil value. While parsing, the DFDL parser checks the nil value for each element in the message. If the value in the bit stream matches the nil value in the DFDL schema, the DFDL parser sets the value in the message tree to NULL. The same check is made when a message tree is converted to a bit stream. If the value in the message tree is NULL, the DFDL parser outputs the nil value from the DFDL schema.

For more information, see The DFDL 1.0 specification, section 13.15.

Graphical Data Mapper support for null values

In the Graphical Data Mapping editor, you can create an element in the message tree as NULL. You can also set the value of a message tree element to NULL, and you can use XPath expressions in your graphical transformations to test if an input element is NULL.

When you map null values, consider the behavior of the Graphical Data Mapping editor. For more information, see Handling nulls in message maps.

When you test to check whether an input element is NULL, you can use any of the following XPath expressions: fn:empty, fn:nilled, or fn:exists. For more information, see Choosing an XPath conditional expression that tests for a nil value in a transform .

ESQL support for null values

Using ESQL, you can set the value of a message tree element to NULL:

SET OutputRoot.XMLNSC.myField VALUE = NULL;

This example is different from SET OutputRoot.XMLNSC.myField = NULL;, which would cause myField to be deleted from the message tree.

The same effect can be achieved by using Java™.

XMLNSC parser support for null values

Typically, the XML parsers (XMLNSC, XMLNS, and XML) do not create null values in the message tree. An empty element or an empty attribute value produces an empty string value in the message tree.

If validation is enabled, the XMLNSC parser detects and processes any xsi:nil attributes in the input document. If the xsi:nil attribute is set to true, and the element is nullable, the attribute's parent element in the message tree is given a null value.

For more information about XML parser support for empty elements and null values, see XMLNSC empty elements and null values and XMLNS empty elements and null values.

JSON parser support for null values

The JSON format supports null as a JSON value type for an object.

When a JSON message includes an object with a null value, the JSON parser sets the value in the message tree to NULL.

When the JSON serializer includes an element in the message tree with a NULL value, the JSON bit stream is constructed as a JSON object with a value of null.

MRM parser support for null values

XML physical format

When parsing, the MRM XML parser can detect and process xsi:nil attributes in the input XML document. If the xsi:nil attribute is set to true, and the element is nullable, the attribute's parent element in the message tree is given a null value.

For information about enabling xsi:nil support in the MRM parser, see Message Sets: XML Null handling options.

The following topics provide more information about handling null values in the MRM parser:

All physical formats

The MRM parser can detect a null value that is represented by an out-of-range value. The null value must be specified in the physical format of the message set.

While parsing, the MRM parser checks the null value for each element in the message. If the value in the bit stream matches the null value in the message set, the MRM parser sets the value in the message tree to NULL.

The same check is made when a message tree is converted to a bit stream. If the value in the message tree is NULL, the MRM parser outputs the null value from the message set.