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

Antonio Fortuny a.fortuny at sitasoftware.lu
Tue Jun 18 15:49:02 CEST 2013


Le 18/06/2013 15:42, Marcos Douglas a écrit :
> 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?
Yep, a text file: assign, reset, append, close. I use an own build 
logger facility (for historical reasons) but I wonder whether Lazarus 
(or FPC) does not have such a logger component.
>
>> 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
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

-- 
Sita Software
*Antonio Fortuny*
Senior Software engineer

220, avenue de la Liberté
L-4602 Niederkorn
Tel.: +352 58 00 93 - 93
www.sitasoftware.lu <http://www.sitasoftware.lu>
Your IT Partner

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130618/cf82f4c7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fdjbahad.jpg
Type: image/jpeg
Size: 2306 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130618/cf82f4c7/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jaeabedc.jpg
Type: image/jpeg
Size: 921 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130618/cf82f4c7/attachment-0001.jpg>


More information about the fpc-pascal mailing list