On Tue, 18 Jun 2013, Marcos Douglas wrote:

On Tue, Jun 18, 2013 at 9:39 AM, Antonio Fortuny
<a.fort...@sitasoftware.lu> wrote:


Le 18/06/2013 14:35, Marcos Douglas a écrit :

Hi,

I need to save some huge XML files in HD.
Today I call WriteXMLFile(Doc, AFileName) but I have XML with 5G, 10G.. 30G...

What the best way to save "line by line"?

Append chuncks of lines to a TFileStream until source XML file is exhausted

But I'm using TXMLDocument class to make the XML.

For each line (log) I do this:
(doesn't matter the information in Par variable)

procedure TXMLLogger.Log;
var
 I: Integer;
 No: TDOMElement;
 Par: TParam;
begin
 No := FDoc.CreateElement('line');
 for I := 0 to FParams.Count-1 do
 begin
   Par := FParams.Items[I];
   TDOMElement(No).SetAttribute(Par.Name, Par.AsString);
 end;
 FRootNode.AppendChild(No);

 FParams.Clear;
end;

At the end, I do some like:
procedure TXMLLogger.Finish;
var
 No: TDOMElement;
begin
 No := FDoc.CreateElement('finish');
 TDOMElement(No).SetAttribute('dh', FmtDateTime(Now));
 FRootNode.AppendChild(No);
end;

And the application call:
procedure TXMLLogger.SaveToFile(const AFileName: string);
begin
 WriteXMLFile(FDoc, AFileName);
end;

So, there is a way to use TXMLDocument but save line by line more faster?


No. The writer already uses a fixed buffer. Your problem is the use of TXMLDocument.

Simply put: logging to XML (worse: using DOM) is a VERY bad idea.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to