Unmarshaling
HydraExpress generated a C++ API that unmarshaled the XML above. Once the data is unmarshaled, you can then analyze and manipulate the data using the type-safe C++ API. Finally, you can generate the XML that conforms to the above schema by taking the modified tree and marshaling it to XML.
Before unmarshaling the XML document, you must create an instance of the C++ type that corresponds with the root element of the XML document. In the purchase order example, this element is the purchaseOrder element, which is namespace qualified. Without the using statement, you would need to qualify the element name when creating an instance:
po::PurchaseOrder po;
But with the using statement, you can simply declare:
PurchaseOrder po;
To unmarshal an XML document, read it into the implementation and invoke the unmarshal() method on the instance.
 
try {
std::ifstream istrm("po1.xml"); //1
RWCString xmlContents;
xmlContents.readFile(istrm);
 
po.unmarshal(xmlContents); //2
 
} catch (const rwsf::XmlParseException &e) {
std::cerr << "Parse error when unmashaling : " << e.what()
<< std::endl;
std::cerr << "Line number: " << e.getLineNumber() << std::endl;
std::cerr << "Column number: " << e.getColumnNumber()
<< std::endl;
return 1;
} catch (const rwsf::Exception &x) {
std::cerr << "Error : " << x.what() << std::endl;
return 1;
}
//1 This and the following two lines read in the XML document.
//2 Calls the unmarshal() method of the PurchaseOrder instance to unmarshal the XML document.
Note that the code above is nearly identical to that in the basic example, except that it uses RWCString from SourcePro C++ rather than a standard library string. Adding the XML namespace qualification does not affect the use of the generated API. HydraExpress takes care of the underlying details.