Working Without Top-Level Element Classes
By default, HydraExpress generates a class for each top-level element in the schema. This class is generated as a convenience. It has methods for marshaling and unmarshaling the element and has the advantage that the class knows the name of the element.
Sometimes, however, large and complex schemas have very many top-level elements, so creating a class for each one greatly increases the generated output. For this reason, HydraExpress offers the flag -notoplevelclasses to suppress classes for top-level elements. In this case, you marshal and unmarshal through the corresponding type class.
For example, specifying this flag when generating the basic example creates only the class PurchaseOrderType, and no class PurchaseOrder. To marshal a purchase order, you would use one of the marshal() methods of PurchaseOrderType. However, there is a problem. The PurchaseOrderType object does not know the name of the top-level element for which it is the type. To solve this problem, HydraExpress creates a class, PoStatics in this case, that holds only static variables for the element names of all top-level elements. For the basic example, this would be:
 
class PoStatics {
public:
static rwsf::XmlName PurchaseOrderElementName;
static rwsf::XmlName CommentElementName;
};
To marshal a purchase order, you would do the following:
 
PurchaseOrderType po;
std:cout << po.marshal(false, PoStatics:PurchaseOrderElementName) << std:endl;
The unmarshal() methods also take the element name as a parameter. This name is used to check that the document being unmarshaled uses the correct name for the element. For the basic example, a call to unmarshal() would look like this:
 
PurchaseOrderType po;
std::ifstream istrm("po.xml");
std::stringstream buffer;
buffer << istrm.rdbuf();
std::string xmlContents(buffer.str());
 
po.unmarshal(xmlContents,PoStatics::PurchaseOrderElementName);
 
When projects are generated with -notopLevelClasses, the generated documentation describes the Statics class and how it is used.