没辙了,大家帮我看看阿(expat)

shaw_xiao2006 2007-05-22 12:33:54
我仿照 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;
}


...全文
392 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yunjian4516 2007-07-15
  • 打赏
  • 举报
回复
mark
king81zhang 2007-07-11
  • 打赏
  • 举报
回复
同问

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧