Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just 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

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,600
    Could it be here?
    Code:
    printf("%d",XML_Parse(p,str,x,1));
    
    XML_SetUserData(p,str);
    XML_SetElementHandler(p,start,end);
    Note that you are setting the element handlers AFTER you parse the string, so naturally they aren't being invoked.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    3

    Wink thank u

    hm tats right,
    i have re-arranged the line. now the callback functions is getting invoked!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •