|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QXmlSerializer Class Reference
[QtXmlPatterns module]

The QXmlSerializer class receives QAbstractXmlReceiver events and produces XML that is sent to a QIODevice. More...

     #include <QXmlSerializer>

Inherits QAbstractXmlReceiver.

Inherited by QXmlFormatter.

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.4.

- List of all members, including inherited members

### Public Functions

- QXmlSerializer ( const QXmlQuery & query, QIODevice * outputDevice )
- const QTextCodec * codec () const
- virtual void item ( const QPatternist::Item & item )
- QIODevice * outputDevice () const
- void setCodec ( const QTextCodec * outputCodec )

- 10 public functions inherited from QAbstractXmlReceiver

## Detailed Description

The QXmlSerializer class receives QAbstractXmlReceiver events and produces XML that is sent to a QIODevice.

QXmlSerializer translates a series of XPath Data Model events(essentially XML) into a sequence of bytes, using a text encoding and XQuery's rules for serialization. This means that it will:

- Declare namespaces when needed
- Appropriately use escaping mechanisms when characters can't be represented in the given encoding,
- Handle line endings appropriately
- Flag an error when it cannot serialize the content, such as when asking to serialize an attribute that is a top-level node or more than one top element is encountered.

If an error occurs during serialization, a bool is thrown as an exception, which QXmlQuery::evaluateToReceiver() will catch and return `false` for.

If the XML should be indented and formatted to be easier to read, use QXmlFormatter.

{XSLT 2.0 and XQuery 1.0 Serialization}

See also http://www.w3.org/TR/xslt-xquery-serialization/ and QXmlFormatter.

## Member Function 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.

QXmlSerializer does not own outputDevice.

### const QTextCodec * QXmlSerializer::codec () const

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

See also setCodec() and ..

### void QXmlSerializer::item ( const QPatternist::Item & item ) `[virtual]`

### 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 own the IO device returned.

### void QXmlSerializer::setCodec ( const QTextCodec * outputCodec )

Sets the codec the serializer will use for encoding its XML output. The output codec is set to outputCodec. 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().