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
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