Procedure for Using the Generated C++ Encode Method
NOTE: As of version 1.1, C++ exceptions are no longer used. Therefore, any application programs that used only try/catch blocks to detect errors will not work properly. The return status code from the encode method is the only mechanism used to report error conditions.
2. Create an instance of an output stream or message buffer object to which the encoded XML message will be written.
3. Create an instance of the generated global element control class to link the generated type class instance with the message buffer or stream instance.
6. If encoding was successful (indicated by return status equal to zero), the start-of-message pointer can be obtained by calling the message buffer getMsgPtr method (note: this assumes encoding using a message buffer was done; if a stream was used, the message has already been written to the target).
7. If encoding failed, the message buffer or stream printErrorInfo method can be invoked to print the reason for failure.
#include "rtxmlsrc/rtXmlCppMsgBuf.h" #include "employee.h" int main (int argc, char** argv) { int i, stat; const char* filename = "message.xml"; OSBOOL trace = TRUE, verbose = FALSE; const OSOCTET* msgptr; // Create buffer and control objects PersonnelRecord value; OSXMLEncodeBuffer buffer; personnelRecord_CC pdu (buffer, value); if (verbose) rtxSetDiag (pdu.getCtxtPtr(), 1); // Populate structure of generated type ... logic to populate structure here ... // Encode stat = pdu.encode(); if (0 == stat) { if (trace) { msgptr = buffer.getMsgPtr(); printf ("encoded XML message:\n"); printf ((const char*)msgptr); printf ("\n"); } } else { printf ("Encoding failed\n"); buffer.printErrorInfo(); return stat; } // Write the encoded message out to the output file buffer.write (filename);
Copyright © Objective Systems 2002-2008 This document may be distributed in any form, electronic or otherwise, provided that it is distributed in its entirety and that the copyright and this notice are included. |
Objective Systems, Inc.55 Dowlin Forge RoadExton, Pennsylvania 19341 http://www.obj-sys.com Phone: (484) 875-9841 Toll-free: (877) 307-6855 (US only) Fax: (484) 875-9830 info@obj-sys.com |