Article View: borland.public.delphi.xml
Article #88Newbie: How to speed up a simple xml parsing task?
From: fokrogh
Date: Thu, 11 Sep 2008 14:59
Date: Thu, 11 Sep 2008 14:59
59 lines
2845 bytes
2845 bytes
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;
Technical Details
Message-ID:
<315b930a-2278-4f1b-b033-5004da1ab724@x35g2000hsb.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!x35g2000hsb.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f5d9b,ed3a284ae4e87a9d,start X-Google-Attributes: gidf5d9b,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!x35g2000hsb.googlegroups.com!not-for-mail From: fokrogh@start.no Newsgroups: borland.public.delphi.xml Subject: Newbie: How to speed up a simple xml parsing task? Date: Thu, 11 Sep 2008 07:59:33 -0700 (PDT) Organization: http://groups.google.com Lines: 61 Message-ID: <315b930a-2278-4f1b-b033-5004da1ab724@x35g2000hsb.googlegroups.com> NNTP-Posting-Host: 84.48.58.178 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1221145174 5655 127.0.0.1 (11 Sep 2008 14:59:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 11 Sep 2008 14:59:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x35g2000hsb.googlegroups.com; posting-host=84.48.58.178; posting-account=ZBuoKwoAAABfF-XV4nwm2fKCnGptUlQP User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe)