An implementation of QAbstractXmlReceiver for transforming XQuery output into unformatted XML.
More...
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output into unformatted XML. This class translates an XQuery sequence, usually the output of an QXmlQuery, into XML.
query.
setQuery(
"doc('index.html')/html/body/p[1]");
query.evaluateTo(&serializer);
First it constructs a query that gets the first paragraph from document index.html
. Then it constructs an instance of this class with the query and myOutputDevice. Finally, it evaluates the query, producing an ordered sequence of calls to the serializer's callback functions. The sequence of callbacks transforms the query output to XML and writes it to myOutputDevice.
QXmlSerializer does the following.
-
Declare namespaces when needed,
-
Use appropriate escaping, when characters can not be represented in the XML,
-
Handle line endings appropriately,
-
Report errors, when it can not serialize the content, e.g., when asked to serialize an attribute that is a top-level node, or when more than one top-level element is encountered.
If an error occurs during serialization, result is undefined unless the serializer is driven through a call to QXmlQuery::evaluateTo().
If the generated XML should be indented and formatted for reading, use QXmlFormatter.
- See also
- XSLT 2.0, XQuery 1.0 Serialization, QXmlFormatter
Constructs a serializer that uses the name pool and message handler in query, and writes the output to outputDevice.
outputDevice must be a valid, non-null device that is open in write mode, otherwise behavior is undefined.
outputDevice must not be opened with QIODevice::Text because it will cause the output to be incorrect. This class will ensure line endings are serialized as according with the XML specification. QXmlSerializer does not take ownership of outputDevice.