extracting data from xml file using c in linux
hi,
I have to extract data from xml file through c coding in linux. I am using expat library function in my coding. whats my problem is ........ xml_set_element_handler(parser,start,end); here start and end are call back function. they are not invoked? please help me! |
Well, it would be better if you could show the code with which u are attempting the same !
|
hi anisha,
this is my code i am using. this code gets compiled with error free. but the call back function start and end are not invoking by the parser!!!. Code: #include<stdio.h> #include<string.h> #include<expat.h> void XMLCALL start(void *userData,const XML_Char *name,const XML_Char **atts); void XMLCALL end(void *userData,const XML_Char *name); void XMLCALL chard(void *ud,const XML_Char *s,int len); int main() { XML_Parser p; p=XML_ParserCreate("US-ASCII"); char *str,*str1; str="<name att='2323' att2='545'>test value</name>"; str1="<name>"; int x=0; x=strlen(str); printf("%d",XML_Parse(p,str,x,1)); XML_SetUserData(p,str); XML_SetElementHandler(p,start,end); return 1; } void XMLCALL start(void *userData, const XML_Char *name,const XML_Char **atts) { printf("%s",name); } void XMLCALL end(void *userData,const XML_Char *name) { printf("End"); } |
Quote:
|
hi anisha,
I modified the coding ,and all the call back functions were get invoked, but i dont know how to assign value to len argument in the chard function. #include<stdio.h> #include<string.h> #include<expat.h> void XMLCALL start(void *str,const XML_Char *name,const XML_Char **atts); void XMLCALL end(void *userData,const XML_Char *name); void XMLCALL chard(void *ud,const XML_Char *s,int len); int main() { XML_Parser p; p=XML_ParserCreate("US-ASCII"); char *str; str="<name1 att='2323' att2='545'> hi every onle<t1 id='123' iq='234'> test value1 </t1> <t2 ix='333'>test value2</t2></name1>"; int x=0; x=strlen(str); XML_SetElementHandler(p,start,end); XML_SetCharacterDataHandler(p,chard); printf("parser status:%d\n",XML_Parse(p,str,x,1)); XML_SetUserData(p,str); return 1; } void XMLCALL start(void *str, const XML_Char *name,const XML_Char **atts) { int i; for(i=0;atts[i];i+=2) { printf("\n%s='%s'\n",atts[i],atts[i+1]); } } void XMLCALL end(void *userData,const XML_Char *name) { printf("End\n"); } void XMLCALL chard(void *ud,const XML_Char *s,int len) { printf("\n chard:%s\n",s); } "new2.c" 52L, 1249C |
Quote:
Besides u have not mentioned where and how this "chard" function is getting called ? |
chard is a call back function.
XML_SetCharacterDataHandler(p,chard); thru this function chard is invoked. the arguments are automatically get assigned |
All times are GMT -5. The time now is 10:40 PM. |