From sreerampraveen@yahoo.com Fri Jun 8 20:18:45 2001 From: sreerampraveen@yahoo.com (p s) Date: Fri, 8 Jun 2001 12:18:45 -0700 (PDT) Subject: [Expat-checkins] expat Usage CDATA node related Query Message-ID: <20010608191845.38165.qmail@web12201.mail.yahoo.com> Hi All, I am trying to parse xml using expat and in the process I need to get data from a CDATA node. Can some one help me how to get data from a CDATA node. Here is my xml here is my C code void start(void *data, const char *el, const char **attr) { int i; FILE *fp4; char acBuff1[50]; /* Attempt to open the dump file */ fp4 = fopen("../tmp/mmtempfile.txt","a"); for (i = 0; i < Depth; i++) fwrite(" ",1,1,fp4); fwrite(el,sizeof(el),1,fp4); for (i = 0; attr[i]; i += 2) { sprintf(acBuff1," %s='%s'", attr[i], attr[i + 1]); if(attr[i+1] == PageName) { iPage = 1; } else if(attr[i +1] == SegmentName) { iSegment = 1; } fwrite(acBuff1,30,1,fp4); fwrite("\n",sizeof("\n"),1,fp4); } fclose(fp4); Depth++; } /* End of start handler */ void end(void *data, const char *el) { if(el == "page") { iPage =0; } else if (el == "segment") { iSegment = 0; } Depth--; } /* End of end handler */ void CDATAstart(void *data) { FILE *fp2; char *cdata; fp2 = fopen("../tmp/mmtempfile.txt","a"); if(iPage == 1 && iSegment == 1) { fwrite("This is in CDATA",16,1,fp2); fwrite("\n",sizeof("\n"),1,fp2); fwrite(cdata,sizeof(cdata),1,fp2); <---- *** Here i need to get the data in CDATA Node ** } fclose(fp2); } void CDATAend(void *data) { ; } void getMessageContent1(FILE *fp3,char *ElementName,char *segment, char *dmmDat a) { XML_Parser p = XML_ParserCreate(NULL); if (! p) { fprintf(stderr, "Couldn't allocate memory for parser\n"); } XML_SetElementHandler(p, start, end); XML_SetCdataSectionHandler(p,CDATAstart,CDATAend); /* Attempt to open the file */ fp3 = fopen("../data/MarketingMessage.xml","r"); if(!fp3) return; for (;;) { int done; int len; len = fread(acBuff, 1, BUFFSIZE, fp3); if (ferror(fp3)) { fprintf(stderr, "Read error\n"); fclose(fp3); exit(-1); } done = feof(fp3); if (! XML_Parse(p, acBuff, len, done)) { fprintf(stderr, "Parse error at line %d:\n%s\n", XML_GetCurrentLineNumber(p), XML_ErrorString(XML_GetErrorCode(p))); fclose(fp3); // exit(-1); } if (done) break; } XML_ParserFree(p); fclose(fp3); return; } The gerMessageContent1 is the function where my parsing starts with arguments as the File pointer for xml file,variable PageName, variable SegmentName and the pointer for storing the data in CDATA node. I was trying this for the last 3days and wasn't fruitfull can some one help me . Thanks in advance Praveen K Sreeram __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/