LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-11-2010, 02:47 AM   #1
karthikmca
LQ Newbie
 
Registered: Feb 2010
Posts: 4

Rep: Reputation: 0
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!
 
Old 02-11-2010, 03:55 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,674
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Well, it would be better if you could show the code with which u are attempting the same !
 
Old 02-11-2010, 06:31 AM   #3
karthikmca
LQ Newbie
 
Registered: Feb 2010
Posts: 4

Original Poster
Rep: Reputation: 0
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");
}

Last edited by karthikmca; 02-11-2010 at 07:02 AM.
 
Old 02-15-2010, 04:33 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,674
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Quote:
whats my problem is ........


xml_set_element_handler(parser,start,end);

here start and end are call back function. they are not invoked?
Where is this xml_set_element_handler(parser,start,end); being defined and called from in the code u have shown ?
 
Old 02-15-2010, 07:18 AM   #5
karthikmca
LQ Newbie
 
Registered: Feb 2010
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
Old 02-15-2010, 07:32 AM   #6
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,674
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Quote:
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.
How are u assigning values to other arguements of "chard" function ?
Besides u have not mentioned where and how this "chard" function is getting called ?
 
Old 02-16-2010, 01:24 AM   #7
karthikmca
LQ Newbie
 
Registered: Feb 2010
Posts: 4

Original Poster
Rep: Reputation: 0
chard is a call back function.

XML_SetCharacterDataHandler(p,chard); thru this function chard is invoked.

the arguments are automatically get assigned
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting data and putting in new file Spinoz Linux - Newbie 5 10-16-2009 03:51 PM
Extracting chunks of data based on variables stored in another file (Perl?) mchriste Linux - Software 2 03-12-2009 01:44 PM
extracting data from html files into one text file adityavpratap Slackware 9 05-10-2007 11:30 AM
Extracting data from file using sed EneWolverine Programming 7 12-29-2006 10:23 AM
help extracting data from csv file willinusf Linux - General 10 10-27-2006 10:10 PM


All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration