QXmlSerializer Class

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

头: #include <QXmlSerializer>
qmake: QT += xmlpatterns
Since: Qt 4.4
继承: QAbstractXmlReceiver
继承者:

QXmlFormatter

该类在 Qt 4.4 引入。

注意: 此类的所有函数 可重入 .

公共函数

QXmlSerializer (const QXmlQuery & query , QIODevice * outputDevice )
const QTextCodec * codec () const
QIODevice * outputDevice () const
void setCodec (const QTextCodec * outputCodec )

重实现公共函数

virtual void atomicValue (const QVariant & value ) override
virtual void 属性 (const QXmlName & name , const QStringRef & value ) override
virtual void characters (const QStringRef & value ) override
virtual void comment (const QString & value ) override
virtual void endDocument () override
virtual void endElement () override
virtual void endOfSequence () override
virtual void namespaceBinding (const QXmlName & nb ) override
virtual void processingInstruction (const QXmlName & name , const QString & value ) override
virtual void startDocument () override
virtual void startElement (const QXmlName & name ) override
virtual void startOfSequence () override

详细描述

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't be represented in the XML,
  • Handle line endings appropriately,
  • Report errors, when it can't 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 .

另请参阅 XSLT 2.0 and XQuery 1.0 Serialization and QXmlFormatter .

成员函数文档编制

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 .

[override virtual] void QXmlSerializer:: atomicValue (const QVariant & value )

重实现: QAbstractXmlReceiver::atomicValue (const QVariant &value).

[override virtual] void QXmlSerializer:: 属性 (const QXmlName & name , const QStringRef & value )

重实现: QAbstractXmlReceiver::attribute (const QXmlName &name, const QStringRef &value).

[override virtual] void QXmlSerializer:: characters (const QStringRef & value )

重实现: QAbstractXmlReceiver::characters (const QStringRef &value).

const QTextCodec *QXmlSerializer:: codec () const

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

另请参阅 setCodec ().

[override virtual] void QXmlSerializer:: comment (const QString & value )

重实现: QAbstractXmlReceiver::comment (const QString &value).

[override virtual] void QXmlSerializer:: endDocument ()

重实现: QAbstractXmlReceiver::endDocument ().

[override virtual] void QXmlSerializer:: endElement ()

重实现: QAbstractXmlReceiver::endElement ().

[override virtual] void QXmlSerializer:: endOfSequence ()

重实现: QAbstractXmlReceiver::endOfSequence ().

[override virtual] void QXmlSerializer:: namespaceBinding (const QXmlName & nb )

重实现: QAbstractXmlReceiver::namespaceBinding (const QXmlName &name).

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.

[override virtual] void QXmlSerializer:: processingInstruction (const QXmlName & name , const QString & value )

重实现: QAbstractXmlReceiver::processingInstruction (const QXmlName &target, const QString &value).

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.

另请参阅 codec ().

[override virtual] void QXmlSerializer:: startDocument ()

重实现: QAbstractXmlReceiver::startDocument ().

[override virtual] void QXmlSerializer:: startElement (const QXmlName & name )

重实现: QAbstractXmlReceiver::startElement (const QXmlName &name).

[override virtual] void QXmlSerializer:: startOfSequence ()

重实现: QAbstractXmlReceiver::startOfSequence ().