[fpc-pascal] How to save a huge XML?

Marcos Douglas md at delfire.net
Tue Jun 18 15:42:07 CEST 2013


On Tue, Jun 18, 2013 at 10:32 AM, Michael Van Canneyt
<michael at freepascal.org> wrote:
>
>
> On Tue, 18 Jun 2013, Marcos Douglas wrote:
>
>> On Tue, Jun 18, 2013 at 9:39 AM, Antonio Fortuny
>> <a.fortuny at 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.

Ideas? Maybe do what Antonio Fortuny said before?

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

Well, this is a request of my client. Other process will read this XML.

Thanks,
Marcos Douglas



More information about the fpc-pascal mailing list