XMLNS 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 XMLNS domain. For advice on good ESQL or Java™ coding practices see Handling null values.
Parsing
Description | XML input parsed by XMLNS | 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"/> | Empty string |
Note that both forms of an empty element result in the same value in the message tree.
Note also that a NULL value is never put into the message tree by the XMLNS parser.
Writing
Description | Value of ‘element' in message tree | XML output from XMLNS parser |
---|---|---|
Empty element value | Empty string | <element/> |
Null element value | NULL | <element/> |
Folder with child elements | No value | <element><childElement/></element> |
Empty elements
- <element/>
- <element></element>
The XMLNS 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 XMLNS parser, it always uses the first form for elements that have a value of "" (the empty string).
Elements with an xsi:nil attribute
The XMLNS parser treats the xsi:nil attribute exactly like any other attribute. When xsi:nil is encountered while parsing, it does not set the value of the parent element to NULL. If you require this behavior you should use the XMLNSC parser. When writing a message tree, if an xsi:nil attribute exists it will be produced in the same way as any other attribute.