CopperSpice API
1.9.2
|
The QXmlFormatter class is an implementation of QXmlSerializer for transforming XQuery output into formatted XML. More...
Public Methods | |
QXmlFormatter (const QXmlQuery &query, QIODevice *outputDevice) | |
void | atomicValue (const QVariant &value) override |
void | attribute (const QXmlName &name, QStringView value) override |
void | characters (QStringView value) override |
void | comment (const QString &value) override |
void | endDocument () override |
void | endElement () override |
void | endOfSequence () override |
int | indentationDepth () const |
void | processingInstruction (const QXmlName &name, const QString &value) override |
void | setIndentationDepth (int depth) |
void | startDocument () override |
void | startElement (const QXmlName &name) override |
void | startOfSequence () override |
Public Methods inherited from QXmlSerializer | |
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 QTextCodec * | codec () const |
void | comment (const QString &value) override |
void | endDocument () override |
void | endElement () override |
void | endOfSequence () override |
void | namespaceBinding (const QXmlName &nb) override |
QIODevice * | outputDevice () 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 () |
The QXmlFormatter class is an implementation of QXmlSerializer for transforming XQuery output into formatted XML. This class is a subclass of QXmlSerializer that formats the XML output to make it easier for humans to read.
QXmlSerializer outputs XML without adding unnecessary whitespace. In particular, it does not add newlines and indentation. To make the XML output easier to read, QXmlFormatter adds newlines and indentation by adding, removing, and modifying sequence nodes that only consist of whitespace. It also modifies whitespace in other places where it is not significant; e.g., between attributes and in the document prologue.
For example, where the base class QXmlSerializer will output the following.
In comparison QXmlFormatter outputs the following.
If you just want to serialize your XML in a human-readable format use QXmlFormatter The default indentation level is 4 spaces. This value can be set to any indentation value using setIndentationDepth().
The newlines and indentation added by QXmlFormatter are suitable for common formats, such as XHTML, SVG, or Docbook, where whitespace is not significant. However, if your XML will be used as input where whitespace is significant, then you must write your own subclass of QXmlSerializer or QAbstractXmlReceiver.
Using QXmlFormatter instead of QXmlSerializer will increase computational overhead and document storage size due to the insertion of whitespace.
The indentation style used by QXmlFormatter remains loosely defined. If a specific indentation style is required then either use the base class QXmlSerializer directly, or write your own subclass of QXmlSerializer or QAbstractXmlReceiver. Alternatively, you can subclass QXmlFormatter and reimplement the callbacks there.
Constructs a formatter that uses the name pool and message handler in query, and writes the result to outputDevice as formatted XML. The given outputDevice is passed directly to QXmlSerializer's constructor.
|
overridevirtual |
Implements QAbstractXmlReceiver::atomicValue()
|
overridevirtual |
Implements QAbstractXmlReceiver::attribute()
|
overridevirtual |
Implements QAbstractXmlReceiver::characters()
|
overridevirtual |
Implements QAbstractXmlReceiver::comment()
|
overridevirtual |
Implements QAbstractXmlReceiver::endDocument()
|
overridevirtual |
Implements QAbstractXmlReceiver::endElement()
|
overridevirtual |
Implements QAbstractXmlReceiver::endOfSequence()
int QXmlFormatter::indentationDepth | ( | ) | const |
Returns the number of spaces QXmlFormatter will output for each indentation level. The default is four.
void QXmlFormatter::setIndentationDepth | ( | int | depth | ) |
Sets depth to be the number of spaces QXmlFormatter will output for level of indentation. The default is four.
|
overridevirtual |
Implements QAbstractXmlReceiver::startDocument()
|
overridevirtual |
Implements QAbstractXmlReceiver::startElement()
|
overridevirtual |
Implements QAbstractXmlReceiver::startOfSequence()