Qt 4.8
|
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output into unformatted XML. More...
#include <qxmlserializer.h>
Public Functions | |
virtual void | atomicValue (const QVariant &value) |
Reimplemented Function More... | |
virtual void | attribute (const QXmlName &name, const QStringRef &value) |
Reimplemented Function More... | |
virtual void | characters (const QStringRef &value) |
Reimplemented Function More... | |
const QTextCodec * | codec () const |
Returns the codec being used by the serializer for encoding its XML output. More... | |
virtual void | comment (const QString &value) |
Reimplemented Function More... | |
virtual void | endDocument () |
Reimplemented Function More... | |
virtual void | endElement () |
Reimplemented Function More... | |
virtual void | endOfSequence () |
Reimplemented Function More... | |
virtual void | item (const QPatternist::Item &item) |
virtual void | namespaceBinding (const QXmlName &nb) |
Reimplemented Function More... | |
QIODevice * | outputDevice () const |
Returns a pointer to the output device. More... | |
virtual void | processingInstruction (const QXmlName &name, const QString &value) |
Reimplemented Function More... | |
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. More... | |
void | setCodec (const QTextCodec *codec) |
Sets the codec the serializer will use for encoding its XML output. More... | |
virtual void | startDocument () |
Reimplemented Function More... | |
virtual void | startElement (const QXmlName &name) |
Reimplemented Function More... | |
virtual void | startOfSequence () |
Reimplemented Function More... | |
Public Functions inherited from QAbstractXmlReceiver | |
QAbstractXmlReceiver () | |
Constructs an abstract xml receiver. More... | |
virtual void | whitespaceOnly (const QStringRef &value) |
This function may be called instead of characters() if, and only if, value consists only of whitespace. More... | |
virtual | ~QAbstractXmlReceiver () |
Destroys the xml receiver. More... | |
Protected Functions | |
QXmlSerializer (QAbstractXmlReceiverPrivate *d) | |
Protected Functions inherited from QAbstractXmlReceiver | |
QAbstractXmlReceiver (QAbstractXmlReceiverPrivate *d) | |
void | sendAsNode (const QPatternist::Item &outputItem) |
Treats outputItem as a node and calls the appropriate function, e. More... | |
Private Types | |
enum | State { BeforeDocumentElement, InsideDocumentElement } |
Private Functions | |
bool | atDocumentRoot () const |
bool | isBindingInScope (const QXmlName nb) const |
void | startContent () |
void | write (const QXmlName &name) |
void | write (const char *const chars) |
void | write (const QString &content) |
void | writeEscaped (const QString &toEscape) |
void | writeEscapedAttribute (const QString &toEscape) |
Additional Inherited Members | |
Protected Variables inherited from QAbstractXmlReceiver | |
QScopedPointer< QAbstractXmlReceiverPrivate > | d_ptr |
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:
First it constructs a QXmlQuery {query} that gets the first paragraph from document index.html
. Then it constructs an instance of this class with the QXmlQuery {query} and QIODevice {myOutputDevice}. Finally, it QXmlQuery::evaluateTo() {evaluates} the QXmlQuery {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 QIODevice {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.
Definition at line 58 of file qxmlserializer.h.
|
private |
Where in the document the QXmlSerializer is currently working.
Definition at line 103 of file qxmlserializer.h.
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.
Definition at line 159 of file qxmlserializer.cpp.
|
protected |
Definition at line 178 of file qxmlserializer.cpp.
|
inlineprivate |
If the current state is neither BeforeDocumentElement or AfterDocumentElement.
Definition at line 185 of file qxmlserializer.cpp.
Referenced by attribute(), and startElement().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 575 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::atomicValue().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 366 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::attribute().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 507 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::endOfSequence(), and QXmlFormatter::startFormattingContent().
const QTextCodec * QXmlSerializer::codec | ( | ) | const |
Returns the codec being used by the serializer for encoding its XML output.
Definition at line 632 of file qxmlserializer.cpp.
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 489 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::comment().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 592 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::endDocument().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 345 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::endElement().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 648 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::endOfSequence().
|
inlineprivate |
Definition at line 402 of file qxmlserializer.cpp.
Referenced by namespaceBinding().
|
virtual |
Reimplemented from QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 540 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::item().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Definition at line 446 of file qxmlserializer.cpp.
Referenced by attribute(), and startElement().
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.
Definition at line 605 of file qxmlserializer.cpp.
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 518 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::processingInstruction().
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.
Definition at line 620 of file qxmlserializer.cpp.
|
inlineprivate |
Closes any open element start tag. Must be called before outputting any element content.
Definition at line 195 of file qxmlserializer.cpp.
Referenced by characters(), comment(), item(), processingInstruction(), and startElement().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 583 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::startDocument().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 307 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::startElement().
|
virtual |
Reimplemented Function
Implements QAbstractXmlReceiver.
Reimplemented in QXmlFormatter.
Definition at line 641 of file qxmlserializer.cpp.
Referenced by QXmlFormatter::startOfSequence().
|
inlineprivate |
Writes out name
.
Definition at line 276 of file qxmlserializer.cpp.
Referenced by attribute(), comment(), endElement(), namespaceBinding(), processingInstruction(), startElement(), writeEscaped(), and writeEscapedAttribute().
|
inlineprivate |
Definition at line 298 of file qxmlserializer.cpp.
|
inlineprivate |
Encodes and writes out content
.
Definition at line 267 of file qxmlserializer.cpp.
|
private |
Escapes content intended as text nodes for elements.
Definition at line 207 of file qxmlserializer.cpp.
Referenced by characters(), and item().
|
inlineprivate |
Identical to writeEscaped(), but also escapes quotes.
Definition at line 236 of file qxmlserializer.cpp.
Referenced by attribute(), and namespaceBinding().