没辙了,大家帮我看看阿(expat)
我仿照 expat给的例子写了如下代码,用vc6编译时,提示
Compiling...
xml.c
I:\XMLPRJ\xml\src\xml.c(71) : warning C4028: formal parameter 2 different from declaration
I:\XMLPRJ\xml\src\xml.c(71) : warning C4024: 'XML_SetElementHandler' : different types for formal and actual parameter 3
xml.obj - 0 error(s), 2 warning(s)
提示参数类型不对,可我看了例子和另外一个网页上的,帖子,就是这么用的阿。
而且第72行代码也是这种用法阿,我实在不知道怎么的了,大家帮我看看阿
源代码如下:
#include "stdio.h"
#include "stdLib.h"
#include "string.h"
#include "expat.h"
#include "myhead.h"
#define MAX_BOOK_DEPTH 10
int current_depth = 0;
BOOK * bookptr;
char bookInfo[MAX_BOOK_DEPTH][20];
#define MAX_BUF 1000
static void XMLCALL startElement(void *userData, const char *el, const char **atts)
{
printf("start\n");
current_depth++;
strcpy(bookInfo[current_depth],el);
}
static void XMLCALL endElement(void *userdata, const char el)
{
printf("end\n");
current_depth--;
}
static void parseCharacter(void *userdata, const XML_Char *s,int len)
{
char * pStr;
pStr = (char *)malloc(len + 1);
strcpy(pStr,s);
pStr[len]= '\0';
if(current_depth == 2)
{
if(strcpy(bookInfo[current_depth],"NAME")==0)
strcpy(bookptr->bookname,pStr);
else if(strcpy(bookInfo[current_depth],"NUM") == 0)
strcpy(bookptr->booknum,pStr);
}
}
void displayInfo()
{
printf("name :%s\n",bookptr->bookname);
printf("num :%s\n",bookptr->booknum);
}
int main(int argc, char ** argv)
{
FILE * pFile;
int isFinal=0;
size_t len;
char buf[MAX_BUF];
XML_Parser parser;
int depth = 0;
parser = XML_ParserCreate(NULL);
if(!parser)
{
fprintf(stderr,"Counldn't allocate memory for parser\n");
return -1;
}
XML_SetElementHandler(parser, startElement, endElement);
XML_SetCharacterDataHandler(parser,parseCharacter);
pFile = fopen("book.xml","r");
if(!pFile)
{
fprintf(stderr,"Counldn't open file\n");
return -1;
}
bookptr = (BOOK *)malloc(sizeof(BOOK));
if(bookptr == NULL)
return -1;
printf("begin\n");
do
{
len = fread(buf,MAX_BUF,1,pFile);
if(len < MAX_BUF)
isFinal = 1;
if(XML_Parse(parser,buf,len,isFinal) == XML_STATUS_ERROR)
{
printf("parse err!!\n");
fprintf(stderr,"Parse error at line %d:\n%s\n",XML_GetCurrentLineNumber(parser),XML_ErrorString(XML_GetErrorCode(parser)));
return -1;
}
}while(!pFile);
free(bookptr);
free(parser);
fclose(pFile);
displayInfo();
return 0;
}