CopperSpice API  1.7.2
QXmlSerializer Class Reference

The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output into unformatted XML. More...

Inheritance diagram for QXmlSerializer:
QAbstractXmlReceiver QXmlFormatter

Public Methods

 QXmlSerializer (const QXmlQuery &query, QIODevice *outputDevice)
 
void atomicValue (const QVariant &value) override
 
void attribute (const QXmlName &name, QStringView value) override
 
void characters (QStringView value) override
 
const QTextCodeccodec () const
 
void comment (const QString &value) override
 
void endDocument () override
 
void endElement () override
 
void endOfSequence () override
 
void namespaceBinding (const QXmlName &nb) override
 
QIODeviceoutputDevice () const
 
void processingInstruction (const QXmlName &name, const QString &value) override
 
void setCodec (const QTextCodec *codec)
 
void startDocument () override
 
void startElement (const QXmlName &name) override
 
void startOfSequence () override
 
- Public Methods inherited from QAbstractXmlReceiver
 QAbstractXmlReceiver ()
 
virtual ~QAbstractXmlReceiver ()
 

Detailed Description

The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output into unformatted XML.

QXmlSerializer translates an XQuery sequence, usually the output of an QXmlQuery, into XML. Consider the example:

QXmlQuery query;
query.setQuery("doc('index.html')/html/body/p[1]");
QXmlSerializer serializer(query, myOutputDevice);
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 will:

  • 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

Constructor & Destructor Documentation

QXmlSerializer::QXmlSerializer ( const QXmlQuery query,
QIODevice outputDevice 
)

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.

Method Documentation

void QXmlSerializer::atomicValue ( const QVariant value)
overridevirtual
void QXmlSerializer::attribute ( const QXmlName name,
QStringView  value 
)
overridevirtual
void QXmlSerializer::characters ( QStringView  value)
overridevirtual
const QTextCodec * QXmlSerializer::codec ( ) const

Returns the codec being used by the serializer for encoding its XML output.

See also
setCodec()
void QXmlSerializer::comment ( const QString value)
overridevirtual

Reimplemented from QAbstractXmlReceiver::comment().

Implements QAbstractXmlReceiver.

void QXmlSerializer::endDocument ( )
overridevirtual
void QXmlSerializer::endElement ( )
overridevirtual
void QXmlSerializer::endOfSequence ( )
overridevirtual
void QXmlSerializer::namespaceBinding ( const QXmlName nb)
overridevirtual
QIODevice * QXmlSerializer::outputDevice ( ) const

Returns a pointer to the output device. There is no corresponding function to set the output device, because the output device must be passed to the constructor. The serializer does not take ownership of its IO device.

void QXmlSerializer::processingInstruction ( const QXmlName name,
const QString value 
)
overridevirtual
void QXmlSerializer::setCodec ( const QTextCodec codec)

Sets the codec the serializer will use for encoding its XML output. The output codec is set to codec. By default, the output codec is set to the one for UTF-8. The serializer does not take ownership of the codec.

See also
codec()
void QXmlSerializer::startDocument ( )
overridevirtual
void QXmlSerializer::startElement ( const QXmlName name)
overridevirtual
void QXmlSerializer::startOfSequence ( )
overridevirtual