In Qt, you can work with XML files in different ways. For example using DOM, SAX, QXmlStream (Reader-Writer). I am interested in the pros and cons of different approaches and their ideology. In which case to use one approach, and which in the other. For example, where is it better to use SAX, and where is QXmlStream (Writer-Reader). It is possible with examples of subtleties.

    1 answer 1

    Everything is very simple and not related to Qt.

    Dom

    pros

    • one call and everything is parsed into a tree that can be explored along and across
    • the tree is easy to modify to save the modified xml
    • usually comes with XPath support, which simplifies various queries

    minuses

    • need a lot of memory. A quick estimate is the size of xml * 3.
    • slow
    • unable to parse incomplete xml

    SAX

    pros

    • fast
    • consumes little memory, good implementations consume very little.

    minuses

    • only for reading
    • just in one run.
    • built on events, it is sometimes difficult to use.
    • difficult to sample

    QXmlStream

    pros

    • i like api - just read by tag
    • must be fast
    • should be memory intensive

    minuses

    • looks like a single pass (need to check)
    • difficult to sample