Default Values
You can specify default values for attributes and elements. In both cases, the default value is generated as a public static constant within the generated class. HydraExpress generates the name of the constant by converting the first letter of the element or attribute name to upper case (if necessary) and appending the suffix DefaultValue. For example, the following schema fragment contains two default values:
 
<xsd:schema ...>
...
<xsd:complexType name="AComplexType">
<xsd:sequence>
...
<xsd:element name="StringElement"
default="unknownElementValue" type="xsd:string"/>
</xsd:sequence>
...
 
<xsd:attribute name="StringAttribute"
default="unknownAttributeValue" type="xsd:string"/>
</xsd:complexType>
...
</xsd:schema>
This makes it convenient for you to see default values, in C++ form, for specific members and to adjust your logic to use the values appropriately by doing comparisons with these default value constants. An example of these public static constant identifiers is shown as they might appear in a generated header file:
 
class AComplexType : public rwsf::XmlBindingHandle{
public:
static const std::string StringElementDefaultValue;
static const std::string StringAttributeDefaultValue;
};
The following example shows how you could use the default value logic:
 
AComplexType myType;
try {
myType.unmarshal(anXmlInputString);
if (myType.getStringElement() ==
AComplexType::StringElementDefaultValue)
{
cout << "The string element for myType is set "
<< "to the default value"
<< endl;
}
} catch (const rwsf::XmlParseException& err) {
cout << "Error unmarshaling xml for myType : "
<< err.what() << endl;
}
The default constructor described in Complex Types initializes the members that represent the element or attribute with the correct DefaultValue constant.
When marshaling, the marshaler performs a comparison with attributes that have default values associated with them. If the attribute value matches the default value constant, the marshaler does not include the attribute in the serialized document. Likewise, if an element has a default value and it is set to the default value, the marshaler serializes empty element content to recognize this.