Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie: How to speed up a simple xml parsing task?

14 views
Skip to first unread message

fok...@start.no

unread,
Sep 11, 2008, 9:46:56 AM9/11/08
to
I have written this simple code to retrieve some attribute values. The
attributes are all located in the beginning of each xml file. However,
it takes VERY long time before the first attribute value is found
(depending on the file size).

Is there a way to speed up the the reading of the xml file - is it
possible to stop the reading execution before the whole file is read?

The progress bar calculation don't seem to work properly. to How can I
make the progress bar show the remaining reading execution?

Regards

Frank Krogh

________________________________

procedure ParseThisFile (myXmlFile: string;fileNumber:integer);
var
Parser: TXmlParser;
XmlFileName, foundValue: string;
DocSize : integer;

begin
Parser := TXmlParser.Create;
Parser.Normalize := True;
Parser.loadfromfile (myXmlFile);
DocSize := StrLen (Parser.DocBuffer);
Parser.StartScan;

While Parser.Scan do
Case Parser.CurPartType of
ptStartTag: begin
foundValue := parser.curattr.value('companyID');
if trim(foundValue) <> '' then
Form1.StringGrid1.cells[1,fileNumber + 1]:= foundValue;
foundValue := parser.curattr.value('businessType');
if trim(foundValue) <> '' then
Form1.StringGrid1.cells[2,fileNumber + 1]:= foundValue;
foundValue := parser.curattr.value('State');
if trim(foundValue) <> '' then
Form1.StringGrid1.cells[3,fileNumber + 1]:= foundValue;
end;
End; {case}
Form1.ProgressBar1.Position := Trunc(( Parser.CurFinal -
Parser.DocBuffer) / DocSize * 100.0);
Parser.Free;
end;

Rob Kennedy

unread,
Sep 11, 2008, 10:31:21 AM9/11/08
to
fok...@start.no wrote:
> I have written this simple code to retrieve some attribute values. The
> attributes are all located in the beginning of each xml file. However,
> it takes VERY long time before the first attribute value is found
> (depending on the file size).
>
> Is there a way to speed up the the reading of the xml file - is it
> possible to stop the reading execution before the whole file is read?

I would expect so, yes. Have you tried it?

Of course, you're still _reading_ the whole file. Otherwise, how would
your call to StrLen give any meaningful answer? You're more interested
in just stopping before the whole file is parsed.

> The progress bar calculation don't seem to work properly. to How can I
> make the progress bar show the remaining reading execution?

I suspect that's exactly what it's doing already. But how much remains
to be read at the time that line runs?

If you don't know what your code is doing, it's frequently an easy task
to step through the code with the debugger. You can watch your program
run line by line. You have a loop; how many times does it execute?

The previous statement is indented as though it's inside the loop, but
it really isn't. The next line indented similarly. Indentation is key to
having human-readable code.

> Parser.Free;
> end;


--
Rob

Jens-Erich Lange

unread,
Sep 12, 2008, 11:27:04 AM9/12/08
to
Which Parser are you using? Is it Stefan Heymanns "LibXmlParser"?
I use that one (mainly because i have Delphi 5 and do XML stuff
manually) and to me it looks lightning fast...

Jens

0 new messages