What is the fastest XML Parser available for Delphi?

Paul picture Paul · Feb 28, 2012 · Viewed 21.2k times · Source

We have reasonably large XML strings which we currently parse using MSXML2

I have just tried using MSXML6 hoping for a speed improvement and have got nothing!

We currently create a lot of DOM Documents and I guess there may be some overhead in constantly interacting with the MSXML2/6 dll

Does anyone know of a better/faster XML component for Delphi?

If anyone can suggest an alternative, and it is faster, we would look to integrate it, but that would be a lot of work, so hopefully the structure would not be too different to that used by MSXML

We are using Delphi 2010

Paul

Answer

teran picture teran · Feb 29, 2012

some time ago I had to serialize record to XML format; for ex:

 TTest = record
    a : integer;
    b : real; 
 end;

to

    <Data>
        <a type="tkInteger">value</a>
        <b type="tkFloat">value</b>
    </Data>

I used RTTI to recursively navigate through record fields and storing values to XML. I've tried few XML Parsers. I did't need DOM model to create xml, but needed it to load it back.

XML contained about 310k nodes (10-15MBytes); results presented in table below, there are 6 columns with time in seconds;
1 - time for creating nodes and write values
2 - SaveToFile();
3 = 1 + 2
4 - LoadFromFile();
5 - navigate through nodes and read values
6 = 4 + 5
enter image description here

MSXML/Xerces/ADOM - are differend vendors for TXMLDocument (DOMVendor)
JanXML doesn't work with unicode; I fixed some errors, and saved XML, but loading causes AV (or stack overflow, I don't remember);
manual - means manually writing XML using TStringStream.

I used Delphi2010, Win7x32, Q8200 CPU/2.3GHz, 4Gb of RAM.

update: You can download source code for this test (record serialization to XML using RTTI) here http://blog.karelia.pro/teran/files/2012/03/XMLTest.zip All parsers (Omni, Native, Jan) are included (now nodes count in XML is about 270k), sorry there are no comments in code.