[Expat-discuss] About caracter handler and attribute value

=?ISO-2022-JP?B?GyRCRWw4NkA1Q1IbKEI=?= m-higa at jaist.ac.jp
Wed Aug 22 21:48:49 CEST 2007


Hi, I have two questions.
1. Can expat get attribute value ?
2. I write C program as folows.
but why on the first line of first cahracter data it cut root open
tag(<biblio>).

(program)
....
void char_handle(void *userdata,const XML_char *s,int len)
{
printf("[CHARACTERDATA] %s\n",s)
}

int main(int argc,char *argv[])
{
char buf[BUSFSIZE};
int eofflag;
size_t len;

XML_PARSER parser;
if((parser=XML_ParserCreate(NULL))==NULL){
fprintf(stderr,"parser creation error\n");
exit(-1);
}

XML_SetCharacterDataHandler(parser,char_handle);
do{
len=fread(buf,sizeof(char),BUFSIZE,stdin);
if(ferror(stdin)){
fprintf(stderr,"file error\n");
exit(-1);
}
eofflag=feof(stdin);
if((XML_Parser(parser,buf,(int)les,eofflag))==0){
fprintf(stderr,"parser error\n");
}
}while(!eofflag);
return 0;
}

(XML file)
<?xml version="1.0"?>
<biblio>
<book>
<author>aaa</author>
<title>bbb</title>
</book>
</biblio>

(output)
[Characterdata] <book id="1"> :<-why?
<author>aaa</author>
<title>bbb</title>
</book>
</biblio>
[Characterdata] <author>aaa</author>
<title>bbb</title>
</book>
</biblio>
[Characterdata] <title>bbb</title>
</book>
</biblio>
[Characterdata] </book>
</biblio>
[Characterdata] </biblio>

Please someone help me.
Regards

Masanori Higashihara


More information about the Expat-discuss mailing list