The Trade Parsing Example
The trade_main.cpp example demonstrates the use of classes generated by HydraExpress to process any elements. This example uses the trade.xsd schema to generate classes for the content of the SOAP body. This section describes the code in the example and presents instructions for running the code generator and compiling the example.
The trade example creates an instance of the class that represents the SOAP envelope, unmarshals the SOAP document into this instance, and retrieves a string that contains the first element in the SOAP body, as shown below:
int main(void)
{
tns::EnvelopeElement e; // 1
// Use a C++ try block to handle errors that can occur when
// unmarshaling XML.In this try block, we will output
// the error message to standard err
try {
std::ifstream istrm("trade.xml");
std::stringstream buffer;
buffer << istrm.rdbuf();
std::string xmlContents(buffer.str());
// Unmarshal the XML into the object model
e.unmarshal(xmlContents); // 2
// get the body from the envelope
tns::BodyType b = e.getBodyElement(); // 3
// get the body entries - there should be one
tns::BodyType::anyVector av = b.getAnyVector(); // 4
std::string s = av[0]; // 5
...
c::GetLastTradePrice tp; // 6
tp.unmarshal(s); // 7
std::cout << "Symbol value: " << tp.getSymbol() // 8
<< std::endl;
} catch (const rwsf::XmlParseException &e) {
std::cerr << "Parse error when unmarshaling : " << e.what()
<< std::endl;
return 1;
} catch (const rwsf::Exception &x) {
std::cerr << "Error : " << x.what() << std::endl;
return 1;
}
return 0;
}