15.1.  The Qt XML Parsers

[ fromfile: xmlparsing.xml id: qtxml ]

XML is widely used as a medium of exchange between programs and as a convenient way to store and transmit hierarchical data. This implies that, for each program that produces XML output, there must be a corresponding program that reads it and produces something meaningful from it. For example: converting the .xmi file produced by Umbrello to a graphic diagram, converting the .ui file produced by designer to a Widget on the screen, converting the .xml files produced by docbook to a .pdf file for printing or to a set of .html files for reading on the web, and so on. To accomplish such a conversion requires the XML file to be parsed. Each of the applications mentioned has a way of parsing XML that uses SAX, DOM, or another XML parsing API. Some APIs, such as DOM and QXmlStreamWriter, have a higher level way of generating XML documents also.

Qt's XML Module includes Qt implementations of two standard (cross-language) XML APIs:

The Simple API for XML, or SAX2, specifies a parse event-driven API for a set of classes that enable low-level, sequential-access parsing for an XML document. It was originally developed in and intended for parsers written in Java. To utilize the SAX API, it is necessary to define callback functions that are passively called in response to various SAX events such as

SAX can process an XML file of almost any size. SAX parsing can proceed only in the forward direction, and SAX applications are expected to do their processing sequentially while the document is being parsed.

The Document Object Model, or DOM, is a standard API that can represent XML elements as objects (i.e., nodes) in a navigable tree structure. Because DOM loads the entire XML file into memory, the maximum file size document that an application can handle is limited by the amount of available RAM. DOM is especially suitable for applications that require random access (as opposed to sequential access) to the various parts of an XML document. It does not provide a way of handling parse errors or modifying elements, but it does provide an API for creating documents.

To use Qt's XML Module, add the following line to your project file:

QT += xml


[93] A processing instruction is an XML note type that can occur anywhere in a document. It is intended to contain instructions to the application.