It's been a while since our last posts in regards to parsing XML documents with Qt. I'd like to give some updates about the expected changes in the upcoming releases. But first, let's summarize what Qt currently provides for reading and writing XML documents.
This module provides implementations for two different models for reading and writing XML files: Document Object Model (DOM) and Simple API for XML (SAX). With DOM model the full XML file is loaded in memory and represented as a tree, this allows easy access and manipulation of its nodes. DOM is typically used in applications where you don't care that much about memory. SAX, on the other hand, is an event based XML parser and doesn't load the whole XML document into memory. Instead it generates events for tokens while parsing, and it's up to the user to handle those events. The application has to implement the handler interfaces (fully, or partially by using
QXmlDefaultHandler). A lot of people find this inconvenient as it forces them to structure their code around this model.
Another problem is that the current implementation of SAX (and as a consequence DOM, since it's implemented using SAX) is not fully compliant with the XML standard. Considering these downsides, Qt does not recommend using SAX anymore, and the decision has been made to deprecate those classes starting from Qt 5.15.
Luckily Qt provides XML streaming classes as a more convenient and XML-standard compliant alternative for working with XML files. You can also check out this blog post to get a quick introduction to XML streaming with Qt.
As it is mentioned above, SAX classes will be deprecated soon, which means that
QDomDocument cannot use them anymore. That's why it has been re-implemented using the
QXmlStreamReader. Qt 6 will switch to the new implementation, but the older Qt versions will still use the old implementation, since the new one brings a few behavioral changes, and we don't want to do this before Qt 6.
What does this change mean for Qt DOM users? Since
QXmlStreamReader is following the XML specification more strictly,
QDomDocument will do the same starting from Qt 6. This will imply the following behavior changes for
<tag attr=" a \n b " />will be equivalent to
<tag attr="a b"/>.
If you are using
QDomDocument and relying on any of these, please consider updating your code and XML documents accordingly.
It would be nice to hear your feedback on how do you currently use Qt’s XML features. Is there anything missing you would like to see? Please let us know in the comments!
Stay up to date with the latest marketing, sales and service tips and news.
Download the latest release here: www.qt.io/download.
Qt 5.12 was developed with a strong focus on quality and is a long-term-supported (LTS) release that will be supported for 3 years.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don’t want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu