JClatricia
New Member
What I am trying to do, leveraging gSOAP:[*]Define data structures in an XML schema[*]Use wsdl2h and soapcpp2 to generate C++ classes representing these structures[*]Read and Write these structures in XML from C++Note that I am not using a Web Service at this point, I am just interested in the XML data binding.If my classes look like:class Base {...}class Der1 : public Base {..}class Der2 : public Base {...}then I can serialize a Base object (which may actually be one of the derived types) using:\[code\]std:fstream myFile;myFile.open("output.out");ctx.os = &myFile; Der1 obj; // or Der2 obj...// ... populate objif (soap_write_Base(ctx, dynamic_cast<Base*>(&obj)) == SOAP_OK){ std::cout << "message serialized" << std::endl;} else { soap_print_fault(ctx, stderr);}\[/code\]and deserialize using:\[code\]std::ifstream myFile;myFile.open("output.out");ctx.is = &myFile;Der1 obj;if (soap_read_Der1(ctx, &obj) == SOAP_OK){ std::cout << "message deserialized" << std::endl; printMessage(msg); //debug} else { soap_print_fault(ctx, stderr);}\[/code\]where ctx is a pointer to the soap context, declared as:\[code\]soap* ctx = soap_new2(SOAP_XML_STRICT, SOAP_XML_INDENT);\[/code\]elsewhere in the code.Can anyone tell me how to change the deserialize code above to be able to read an object without knowing up-front if it is a Der1, Der2, or Base object?Thank you!