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

Sven Barth pascaldragon at googlemail.com
Tue Jun 18 19:16:30 CEST 2013


On 18.06.2013 16:01, Michael Van Canneyt wrote:
>
>
> On Tue, 18 Jun 2013, Marcos Douglas wrote:
>
>> On Tue, Jun 18, 2013 at 10:44 AM, Michael Van Canneyt
>> <michael at freepascal.org> wrote:
>>>
>>>
>>> On Tue, 18 Jun 2013, Marcos Douglas wrote:
>>>
>>>>> 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.
>>>
>>>
>>> Under no circumstances should you use TXMLDocument for this.
>>
>> So, where is recommended to use TXMLDocument class?
>
> General XML processing. Small documents.
>
> You should be aware that the DOM always has the whole XML document in
> memory, plus a substantial amount of overhead. This is not something FPC
> specific, but is inherent in the DOM model. (a W3 spec)
>
> Regardles of XML or not: keeping logs in memory is simply a bad idea.
> You can buffer them for performance reasons, but after some time you
> must write to file.
>
> The DOM model does not allow this.

Maybe we should implement a simple API for just writing an XML to a 
stream. Something like SAX only the other way round. E.g.

=== example code begin ===

xml.StartNode('outer');
xml.AddAttribute('foo', 42);
xml.StartNode('blubb');
xml.AddAttribute('bar', 'test');
xml.AddAttribute('bar2', 'xyz');
xml.SetValue('Hello');
xml.EndNode;
xml.StartNode('blubb');
xml.AddAttribute('bar2', 'alpha');
xml.AddAttribute('bar', 'beta');
xml.SetValue('World');
xml.EndNode;
xml.EndNode;

=== example code end ===

would the result in

=== xml begin ===

<outer foo="42">
   <blubb bar="test" bar2="xyz">
     Hello
   </blubb>
   <blubb bar2="alpha" bar="beta">
     Hello
   </blubb>
</outer>

=== xml end ===

Regards,
Sven



More information about the fpc-pascal mailing list