3 Replies Latest reply on Sep 18, 2018 1:12 PM by Saravana85

    Converting a XML file and load into FML32 buffer in tuxedo 12

    Saravana85

      Hi,

       

      I am working on a POC for my current project which we need to receive a XML through a tuxedo service. In order to parse the received XML in the tuxedo, we chose the XMLTOFML32 conversion since it is offered by tuxedo. Since I am very new to TUXEDO, facing lot of challenges and certainly need a guidance from the tuxedo expertise. Below is my sample XML and my fld defintion table

       

      XML:

      <?xml version="1.0" encoding="UTF-8"?>

      <POCREQ>

           <INDATA>VALID</INDATA>

           <SERVICE>XMLSERVICE</SERVICE>

           <OUTDATA>TEXT</OUTDATA>

           <PARENT>

                <CHILD1>AAAA</CHILD1>

                <CHILD2>BBBB</CHILD2>

           </PARENT>

      </POCREQ>

       

      Field table:

       

      # name          number  type    flags   comments

      INDATA           200     string      -      -      

      SERVICE        300      string - -

      OUTDATA       400      string - -

      PARENT         500      fml32 - -

      CHILD1           600      string - -

      CHILD2           700      string - -

      POCREQ        800      fml32 - -

       

       

      My Code:

      ______________________________________________________________________________

      void XMLSERVICE(TPSVCINFO *rqst)

      {

      printf("Inside XMLSERVICE in XMLSERVER.c \n");

      char *xmlbuf, *fmlbuf;

      char *requestfml;

      char *responsexml, *responsefml;

      char *subfml;

      char *stock_name;

      char *fldname;

      FILE *stock_data;

      FLDID32 fieldid = FIRSTFLDID;

      FLDID32 lastfieldid = FIRSTFLDID;

      FLDOCC32 oc;

      FLDLEN32 len = 0;

      int fmlrc, rc;

      long stock_amount = 0;

      float stock_price = 0;

       

       

      if((xmlbuf = (char *) tpalloc("XML", NULL, XMLMAXSIZE)) == NULL) {

      (void) fprintf(stderr,"Error allocating send buffer\n");

      exit(1);

      }

       

       

      if((fmlbuf = (char *) tpalloc("FML32", NULL, XMLMAXSIZE)) == NULL) {

      (void) fprintf(stderr,"Error allocating receive buffer\n");

      tpfree(xmlbuf);

      exit(1);

      }

      if((subfml = (char *) tpalloc("FML32", NULL, XMLMAXSIZE)) == NULL) {

      (void) fprintf(stderr,"Error allocating receive buffer\n");

      tpfree(xmlbuf);

      tpfree(subfml);

      exit(1);

      }

      printf(" SSSSSSSSSSSSSSSS 11111111111 \n");

      memset(xmlbuf, NULL, XMLMAXSIZE);

      if ((stock_data = fopen("1.xml", "rt")) != NULL) {

      fread(xmlbuf, sizeof(char), XMLMAXSIZE, stock_data);

      fclose(stock_data);

      }

      else {

      userlog("Can not find xml data file: RES.xml");

      }

      printf(" SSSSSSSSSSSSSSS 222222222222 [ %s ]\n", xmlbuf);

      rc = tpxmltofml32(xmlbuf, NULL, (FBFR32 **) &fmlbuf, NULL, 0);

      if(rc == -1) {

      userlog("Error convert stock data from XML to FML32");

      tpfree(xmlbuf);

      tpfree(fmlbuf);

      tpreturn(TPFAIL, -1, NULL, 0, 0);

      }

      printf(" SSSSSSSSSSSSSSS 3333333333333 %d \n", rc);

      //strcpy(responsexml, (char *)xmlbuf);

      printf(" SSSSSSSSS FML BUF SSSSSS [ %s ] \n", fmlbuf);

      requestfml = rqst->data;

      //rqst->data = requestfml

      printf(" 111111111 REQUEST DATA 11111111 [ %s ] \n", rqst->data);

      stock_name = Fgetalloc32((FBFR32 *)requestfml, Fldid32("INDATA"), 0, &len);

      printf(" AAAAAAAA DATA AAAAAAAAA %s == [ %d ]\n", stock_name, Fldid32("RESPONSE"));

      if ((stock_name == NULL) || (strlen(stock_name) == 0)) {

      userlog("Error get request data");

      if(stock_name)

      free(stock_name);

      tpfree(xmlbuf);

      tpfree(fmlbuf);

      tpreturn(TPFAIL, -1, NULL, 0, 0);

      }

       

       

      responsexml = rqst->data;

      do {

      fmlrc = Fnext32((FBFR32 *) fmlbuf, &fieldid, &oc, NULL, NULL);

      printf("AAAA : fmlrc [ %d ] \n", fmlrc);

      printf("AAAA : fieldid [ %d ] \n", fieldid);

      printf(" FIELD NAME ====> [ %s ] \n", Fname32(fieldid));

      if (fmlrc < 0) {

      userlog("Error get stock data");

      free(stock_name);

      tpfree(xmlbuf);

      tpfree(fmlbuf);

      tpreturn(TPFAIL, -1, NULL, 0, 0);

      }

      else if (fmlrc == 0) {

      tpreturn(TPSUCCESS, 0, rqst->data, rqst->len, 0);

      break;

      }

      else {

      printf( " SSSSSSSSSSSSS ELLLLLSSSSSEEEEEEEE \n");

       

      if ( fieldid == Fldid32("PARENT") ) {

      printf( " ________ INSIDE PARENT _______ \n");

      subfml = Fgetalloc32((FBFR32 *)fmlbuf, fieldid, oc, &len);

      if (subfml) {

      printf( " ________ INSIDE PARENT SUBXML  _______ \n");

      do{

      fmlrc = Fnext32((FBFR32 *) subfml, &fieldid, &oc, NULL, NULL);

      printf("AAAA : fmlrc [ %d ] \n", fmlrc);

      printf("AAAA : fieldid [ %d ] \n", fieldid);

      printf(" FIELD NAME ====> [ %s ] \n", Fname32(fieldid));

       

      if (fmlrc < 0) {

      userlog("Error get stock data");

      free(stock_name);

      tpfree(xmlbuf);

      tpfree(fmlbuf);

      tpreturn(TPFAIL, -1, NULL, 0, 0);

      }else if (fmlrc == 0) {

      break;

      }

      } while(1);

      free(subfml);

      }

      }

      }

      lastfieldid = fieldid;

      } while(1);

       

       

       

       

      /* Return the transformed buffer to the requestor. */

      free(stock_name);

      tpfree(xmlbuf);

      tpfree(fmlbuf);

      tpreturn(TPSUCCESS, 0, responsexml, strlen(responsexml), 0);

      }

      _____________________________________________________________________

       

      Using the above code I couldn't print the CHILD1 & CHILD2 fieldid and value. In other words, I need a sample code to parse a XML which has a parent child combination nodes.

       

      Thanks in advance for your help.

      Saravana

        • 1. Re: Converting a XML file and load into FML32 buffer in tuxedo 12
          user9130018

          You have two Fnext32 loops (external and internal for "parent" tag) that are using the same 'fieldid' and 'oc' variables. Add two new variables: fieldid2=FIRSTFLDID; occ2=0 just after printf with "INSIDE PARENT SUBXML" and use them in internal Fnext32 loop

          1 person found this helpful
          • 2. Re: Converting a XML file and load into FML32 buffer in tuxedo 12
            Saravana85

            Thanks a lot user9130018.. It worked and I can print the Child tag values... And I have one more question.. Sorry to bug you again..  I need to find out the number of occurrances of the PARENT tag in my sample XML..

             

            Sample XML:

            <?xml version="1.0" encoding="UTF-8"?>

            <POCREQ>

                 <INDATA>VALID</INDATA>

                 <SERVICE>XMLSERVICE</SERVICE>

                 <OUTDATA>TEXT</OUTDATA>

                 <PARENT>

                      <CHILD1>AAAA</CHILD1>

                      <CHILD2>BBBB</CHILD2>

                 </PARENT>

                 <PARENT>

                       <CHILD1>CCCC</CHILD1>

                      <CHILD2>DDDD</CHILD2>

                 </PARENT>

                 <PARENT>

                      <CHILD1>EEEE</CHILD1>

                      <CHILD2>FFFF</CHILD2>

                 </PARENT>

                 <PARENT>

                      <CHILD1>GGGG</CHILD1>

                      <CHILD2>HHHH</CHILD2>

                 </PARENT>

            </POCREQ>

             

            And Here is my code..

             

            void XMLSERVICE(TPSVCINFO *rqst)

            {

            printf("Inside XMLSERVICE in XMLSERVER.c \n");

            char *xmlbuf, *fmlbuf;

            char *requestfml;

            char *responsexml, *responsefml;

            char *subfml;

            char *stock_name;

            char *fldname;

            FILE *stock_data;

            FLDID32 fieldid = FIRSTFLDID;

            FLDID32 lastfieldid = FIRSTFLDID;

            FLDID32 fieldid2=FIRSTFLDID;

            FLDOCC32 occ2=0;

            FLDOCC32 oc;

            FLDLEN32 len = 0;

            int fmlrc, rc;

            long stock_amount = 0;

            float stock_price = 0;

             

             

            if((fmlbuf = (char *) tpalloc("FML32", NULL, XMLMAXSIZE)) == NULL) {

            (void) fprintf(stderr,"Error allocating receive buffer\n");

            tpfree(xmlbuf);

            exit(1);

            }

            if((subfml = (char *) tpalloc("FML32", NULL, XMLMAXSIZE)) == NULL) {

            (void) fprintf(stderr,"Error allocating receive buffer\n");

            tpfree(xmlbuf);

            tpfree(subfml);

            exit(1);

            }

             

             

            requestfml = rqst->data;

            printf("__________________________________\n");

            Fprint32((FBFR32 *)requestfml);

            printf("__________________________________\n");

             

            printf(" 111111111 REQUEST DATA 11111111 [ %s ] \n", rqst->data);

            if ( oc = Ffindocc32((FBFR32 *) requestfml, PARENT, NULL, 0) < 0 ){

                 F_error32("FAIL TO FIND OCCURRANCES");

            }

            printf(" ========> OCCURRANCES OF PARENT =====> [ %d ] \n", Ffindocc32((FBFR32 *) requestfml, PARENT, NULL, 0));

             

             

            /* Return the transformed buffer to the requestor. */

            free(stock_name);

            tpfree(xmlbuf);

            tpfree(fmlbuf);

            tpreturn(TPSUCCESS, 0, responsexml, strlen(responsexml), 0);

            }

             

            And I am always getting -1 as the output for occurrances. Can you please help on that too..?

             

            Many thanks in advance.

            Regards,

            Saravana.

            • 3. Re: Converting a XML file and load into FML32 buffer in tuxedo 12
              Saravana85

              Very Good Morning... And my day starts with a positive note as I've figured it out.. I should've used Foccur32 function instead of Ffindocc32. Now it's working fine. Since I am very new to Tuxedo functions, I am slowly exploring all these. So do please bear with me if I have asked any silly questions. Certainly I will come up with some questions based on my business requirements. So in advance I'm asking for your help. Thank you so much. And have a Wonderful day...