Expat XML_Parse() problem

P

panky.tiwari

Hi,
I have an XML File while I am parsing through Expat and in Chunks.
The code snippet I am using

XML_Parser p = XML_ParserCreate(NULL);
if(!p)
{
print_k("Unable to create Parser\n");
break;
}
XML_SetUserData(p, (void *)this);
XML_SetElementHandler(p, start, end);
infile = openfile(filename, mode);

buffer = (char*) malloc((BUFFSIZE + 1) * sizeof(char));
if(!buffer)
{
print_k("Unable to allocate memory!\n");
break;
}
int num_read = 0;
while ((num_read = readfile(infile, buffer, BUFFSIZE)) > 0)
{
int done = num_read < BUFFSIZE? 1: 0;
starttimer(start);
if (XML_Parse(p, buffer, num_read, done) ==
XML_STATUS_ERROR)
{
print_k("Error in Parsing");
break;
}
stoptimer(stop);
print_k("time taken = %d\n", stop-start);
}
XML_ParserFree(p);
if(buffer){
free(buffer);
buffer = NULL;
}
if(infile){
closefile(infile);
infile = NULL;
}

For the first time if I parse the process, It is quite fast. The
XML_Parse returns in almost no time. But if I parse it the second
time, XML_Parse function takes large time (twice, sometimes four times
even) slowing down the overall time taken to complete the parsing.
I have no clue regarding this. It is due to the way I am using expat
or the data set (XML file I am having) or other.
Any help is welcome
 
P

panky.tiwari

Hi,
I have an XML File while I am parsing through Expat and in Chunks.
The code snippet I am using

XML_Parser p = XML_ParserCreate(NULL);
if(!p)
{
print_k("Unable to create Parser\n");
break;
}
XML_SetUserData(p, (void *)this);
XML_SetElementHandler(p, start, end);
infile = openfile(filename, mode);

buffer = (char*) malloc((BUFFSIZE + 1) * sizeof(char));
if(!buffer)
{
print_k("Unable to allocate memory!\n");
break;}

int num_read = 0;
while ((num_read = readfile(infile, buffer, BUFFSIZE)) > 0)
{
int done = num_read < BUFFSIZE? 1: 0;
starttimer(start);
if (XML_Parse(p, buffer, num_read, done) ==
XML_STATUS_ERROR)
{
print_k("Error in Parsing");
break;
}
stoptimer(stop);
print_k("time taken = %d\n", stop-start);
}
XML_ParserFree(p);
if(buffer){
free(buffer);
buffer = NULL;
}
if(infile){
closefile(infile);
infile = NULL;
}

For the first time if I parse the process, It is quite fast. The
XML_Parse returns in almost no time. But if I parse it the second
time, XML_Parse function takes large time (twice, sometimes four times
even) slowing down the overall time taken to complete the parsing.
I have no clue regarding this. It is due to the way I am using expat
or the data set (XML file I am having) or other.
Any help is welcome

the observation is only on Windows
 
P

panky.tiwari

I am making a call back to parse the internal nodes of the XML Data.
Is that causing any delay.
What is the best practice to parse a complete XML file?
Any Ideas
 
J

Jürgen Kahrs

I am making a call back to parse the internal nodes of the XML Data.
Is that causing any delay.
What is the best practice to parse a complete XML file?
Any Ideas

It would be easier to help you if you qouted
the context of your question. I guess you didnt
quote the context because you dont know how to
do this with GoogleNews.

Anyway, have you considered using a scripting
language that support all kinds of "callbacks"
in a syntax that is much short and easier to
read ? There are many scripting languages that
support parsing XML files. Have a look at this
one:

http://home.vrweb.de/~juergen.kahrs/gawk/XML/xmlgawk.html#Printing-an-outline-of-an-XML-file
 
P

panky.tiwari

Thanks for the help.

The error was not coming from expat. It was coming from my deque
implementation.
After clearing out the deque, I was not calling deque.clear() and
using the same deque again. I still dont have clue How it was
instrumental in raising the time of XML_Parse() function execution.
But, my problem is solved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top