XMLNSC empty elements and null values
Empty elements and null values occur frequently in XML documents.
A robust message flow must be able to recognize and handle empty elements and null values. Similarly, elements in a message tree might have a NULL value, an empty value, or no value at all. This topic explains the parsing and writing of these values by the XMLNSC domain. For details on processing null values in Graphical Data Maps and ESQL, see Handling null values.
Parsing
Description | XML input parsed by XMLNSC | Value of 'element' in message tree |
---|---|---|
Empty element value | <element/> |
Empty string |
Empty element value | <element></element> |
Empty string |
Folder with child elements | <element><childElement/></element> |
No value |
Nil element value | <element
xsi:nil="true"/> |
No value and a child xsi:nil
attribute with the value 'true'. |
Both forms of an empty element result in the same value in the message tree.
Writing
Description | Value of 'element' in message tree | XML output from XMLNSC parser |
---|---|---|
Empty element value | Empty string | <element/> |
Null element value | NULL | <element/> |
Folder with child elements | No value | <element><childElement/></element> |
Nil element value | Empty string, NULL, or Folder | <element xsi:nil="true"/> Note that
the XMLNSC parser produces only |
Empty elements
- <element/>
- <element></element>
The XMLNSC parser treats both forms in the same way. The element is added to the message tree with a value of "" (the empty string).
When a message tree is produced by the XMLNSC parser, it always uses the first form for elements that have a value of "" (the empty string) in the input XML message.
Elements with an xsi:nil
attribute
If validation is enabled for the flow, the XMLNSC parser performs the following validations:
- The 'nillable' property of an element definition in the XML schema
is set to 'true'.
If the element in the document has an
xsi:nil
attribute with the value 'true', the element must not have a value, or contain any child elements. - The 'nillable' property of an element definition in the XML schema is set to 'false'.
The element in the input document must not have an
xsi:nil
attribute.
If an element in the input document has an xsi:nil
attribute, the XMLNSC
parser creates an element in the message tree with no value, and a child
xsi:nil
attribute with the value 'true' or 'false'.
When a message tree is written to a bit stream by the XMLNSC parser, if the value of the
element is empty, NULL, or no value, and the element has no child elements, the
element is written as <element/>
. If the element has an
xsi:nil
attribute, it is written exactly like any other
attribute.
Note that
the XMLNSC parser produces only xsi:nil
attributes that are already in the message tree. It does not
automatically produce xsi:nil
attributes for
all message tree elements that have a NULL value and are
'nillable'.