nillable Elements
An element that contains the attribute nillable="true" may be represented in an instance document as either an empty element or an element that holds the content specified in the schema. For example, the declaration below specifies that an element of type NillableDecimal may either be empty or contain an xsd:decimal value:
<element name="NillableDecimal" type="xsd:decimal"
HydraExpress creates a pair of boolean methods for working with nillable elements. The is<identifier>ValueSet method returns true if the element holds a value, or false if it is null. The set<identifier>ValueSet method sets the state directly.
When <identifier> is represented by a class created by HydraExpress, calling set<identifier> updates is<identifier>ValueSet. That is, setting the value to an object that is nil sets is<identifier>ValueSet to false, while setting the value to an object that is not nil sets is<identifier>ValueSet to true. For elements that are represented by built-in types, setting the value does not change the state of is<identifier>ValueSet.
An element may be optional as well as being nil. In that case, the is<identifier>Set method determines whether the marshal method produces an element. The is<identifier>ValueSet method determines whether the element produced is empty.
Notice that whether an element is omitted, marshaled as a nil value, or fully marshaled depends on the state of is<identifier>Set (if present) and is<identifier>ValueSet in the containing object. This produces the correct behavior in most cases. Notice, however, that it is possible for the contained element to be inconsistent with the is<identifier>ValueSet flag, as shown in the samples below:
PurchaseOrder po;
Comments comments; // By default, contains no
// value for xsi:nil
po.setComments(comments); // Updates isCommentsValueSet
// to true
po.getComments.setXsiNil(true); // Error! does not update
// isCommentsValueSet
For collections, as described in the next section, the is<identifier>ValueSet flag is implemented as a std:vector of flags.