TOC PREV NEXT INDEX


XML C Pull-Parser Based Decode Functions


XML C pull-parser based decode functions handle the decoding of simple XSD types. Calls to these functions are assembled in the C source code generated by the XBinder compiler to decode complex XML schema-based messages. In general, these complement the encoding model in which individual functions exist for each type. This differs from the SAX-based functions described below which use a different model.

As an example, the code documented above to encode a simple boolean value can be reversed to decode the value:

   OSCTXT 	ctxt;
 
   int   	 stat;
 
   const char* filename = "message.xml";
 
   OSBOOL value;
 

 
   /* Init context structure */
 

 
   stat = rtXmlInitContext (&ctxt);
 
   if (0 != stat) {
 
      printf ("Context initialization failed.\n");
 
      rtxErrPrint (&ctxt);
 
      return stat;
 
   }
 

 
   /* Create input source object */
 

 
   stat = rtxStreamFileCreateReader (&ctxt, filename);
 
   if (0 != stat) {
 
      printf ("Unable to open file input stream.\n");
 
      rtxErrPrint (&ctxt);
 
      return stat;
 
   }
 

 
   /* Match expected start tag */
 

 
   stat = rtXmlpMatchStartTag (&ctxt, OSUTF8("boolValue"), -1);
 
   if (0 != stat) {
 
      printf ("parse initial tag failed\n");
 
      rtxErrPrint (&ctxt);
 
      return stat;
 
   }
 

 
   /* Decode boolean value */
 

 
   stat = rtXmlpDecBool (&ctxt, &value);
 
   if (0 != stat) {
 
      printf ("decode boolean failed\n");
 
      rtxErrPrint (&ctxt);
 
      return stat;
 
   }
 

 
   /* Match expected end tag */
 

 
   stat = rtXmlpMatchEndTag (&ctxt, 0);
 
   if (0 != stat) {
 
      printf ("parse initial tag failed\n");
 
      rtxErrPrint (&ctxt);
 
      return stat;
 
   }
 

 
   rtxStreamClose (&ctxt);
 
   rtxFreeContext (&ctxt);
 

 


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 Road
Exton, 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

TOC PREV NEXT INDEX