In XML, one can omit an element to express lack of value or use an empty element.
Sometimes it is desirable to represent an unshipped item, unknown information, or inapplicable information explicitly with an element, rather than by an absent element.
The trouble with using an empty element <foo></foo>
is that the emptiness would no longer matches the specified type like xs:positiveInteger
. It is possible to form a xs:union
of xs:positiveInteger
and an xs:enumeration
with only empty string in it to allow either poistive integers or empty string. However, technically speaking, an empty string is different from pure emptiness. In terms of code, it's the difference between null
and ""
, or in Scala, None
and Some("")
.
XML Schema resolves this issue by introducing a special attribute called xsi:nil
. By writing
<price xsi:nil="true" />