1 Reply Latest reply: May 20, 2011 5:13 AM by RameshkumarT RSS

    Trouble with xml parsing

    RameshkumarT
      typedef struct {
      xmlctx *xctx;
      oratext *elem;
      } saxctx;

      oratext *xml_value;
      char *xml_element;


      short process_record (void)
      {

           parse_xml(column->column_value,column->actual_value_length);

           puts("after parse");
           printf("Element : %s\n",xml_element);
           printf("Data : %s\n",xml_value);

      }

      static XMLSAX_CHARACTERS_F(characters, ctx, ch, len)
      {
           saxctx sc = (saxctx ) ctx;
           xml_element=sc->elem;
           xml_value=ch;

           printf("Element : %s\n",xml_element);
           printf("Data : %s\n",xml_value);

      return 0;
      }

      static xmlsaxcb saxcb = {
      startDocument,
      endDocument,
      startElement,
      endElement,
      characters
      };



      int parse_xml(char *addr_buf,int buf_len )
      {
      xmlctx *xctx;
      saxctx sc;
      xmlerr ecode;


      puts("Creating XML context...");

           if (!(xctx = XmlCreate(&ecode, (oratext *) "saxsample_xctx", NULL)))
      {
      output_msg("Failed to create XML context, error %u\n", (unsigned) ecode);
      return 1;
      }


      output_msg("Parsing XML ...\n");

      if (ecode = XmlLoadSax(xctx, &saxcb, &sc, "buffer", addr_buf, "buffer_length", buf_len,
                     "validate", TRUE, "discard_whitespace", TRUE, NULL))
           return 1;

      XmlDestroy(xctx);               /* terminate XML package */

      return 0;
      }


      I am using the sample code "SAXSample.c" and am passing a buffer that contains an xml.I need to capture element and its corresponding data and send it to another function which can process it.I declared global variables for this.But am facing issues .The printf inside "XMLSAX_CHARACTERS_F" is working but the same is not working inside "process_record". I am new to programming and trying my best. Any help appreciated.