Results 1 to 3 of 3
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 ...
- 02-15-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 3
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?
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");
}
please help me
- 02-15-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Could it be here?
Note that you are setting the element handlers AFTER you parse the string, so naturally they aren't being invoked.Code:printf("%d",XML_Parse(p,str,x,1)); XML_SetUserData(p,str); XML_SetElementHandler(p,start,end);Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 02-16-2010 #3Just Joined!
- Join Date
- Feb 2010
- Posts
- 3
thank u
hm tats right,
i have re-arranged the line. now the callback functions is getting invoked!


Reply With Quote