When it deals with parsing some (textual) content, two directions are
usually envisaged. In the XML world, you have usually to make a choice
between:
- A DOM parser, which creates an in-memory tree structure of objects mapping
the XML nodes;
- A SAX parser, which reads the XML content, then call pre-defined
events for each XML content element.
In fact, DOM parsers use internally a SAX parser to read the XML content.
Therefore, with the overhead of object creation and their property
initialization, DOM parsers are typically three to five times slower than SAX.
But, DOM parsers are much more powerful for handling the data: as soon as it's
mapped in native objects, code can access with no time to any given node,
whereas a SAX-based access will have to read again the whole XML content.
Most JSON parser available in Delphi use a DOM-like approach. For instance,
the DBXJSON unit included
since Delphi 2010 or the SuperObject or DWS libraries create a
class instance mapping each JSON node.
In a JSON-based Client-Server ORM like ours, profiling shows that a lot of
time is spent in JSON parsing, on both Client and Server side. Therefore, we
tried to optimize this part of the library.