Fastest possible XML handling in Delphi for very large documents Fastest possible XML handling in Delphi for very large documents xml xml

Fastest possible XML handling in Delphi for very large documents


If I understood your question correctly, you have known data structure and you are modifying data - not XML structure of file.

Under these condition and if performance is crucial, then you could try with direct text manipulation - skip XML parsing.

Read from stream, use some fast text search algorithm e.g. Boyer-Moore, to find places where you need to modify data, do your modification and output data into another stream.

This would be one-pass, no XML parsing, no in-memory XML tree building.


SAX is worth considering instead of a DOM parser.

With DOM you pay the overhead of loading up the document, but once loaded data can be accessed and updated quickly.

With SAX you have to write handlers for begin-element, end-element, etc, but you have much more flexibility in what you do as you go along.

Although it probably doesn't help your situation, SAX is very useful where you are searching because you can halt the parsing at any point, so once you have found what you wanted you can stop.

If your program does not need to have parsed all the data before it knows what changes to make, you could write SAX handlers that just updated the data when it was read and otherwise passed it through, so it would stream the data rather than having to load it all into any sort of memory structure. This would make the solution very scalable as you wont hit memory constraints with very large files.

For what it's worth, I tend to use the MSXML DOM and SAX parsers. It can be argued that they are not the best performing, I argue that there are probably more people working on improving them, so they will get better and better.


I'm very satisfied with NativeXML from SimDesign. It also includes a special version called FastXML, which I didn't test yet, but is told to be, well, fast.