com.trolltech.qt.xmlpatterns
Class QXmlFormatter

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.xmlpatterns.QAbstractXmlReceiver
                  extended by com.trolltech.qt.xmlpatterns.QXmlSerializer
                      extended by com.trolltech.qt.xmlpatterns.QXmlFormatter
All Implemented Interfaces:
QtJambiInterface, java.lang.Cloneable

public class QXmlFormatter
extends QXmlSerializer

The QXmlFormatter class is an implementation of QXmlSerializer for transforming XQuery output into formatted XML. QXmlFormatter 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 would output this:

<a><b/><c/><p>Some Text</p></a>
QXmlFormatter outputs this:
<a>
   <b/>
   <c/>
   <p>Some Text</p>
</a>
If you just want to serialize your XML in a human-readable format, use QXmlFormatter as it is. The default indentation level is 4 spaces, but you can set your own indentation value 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.

Note that using QXmlFormatter instead of QXmlSerializer will increase computational overhead and document storage size due to the insertion of whitespace.

Note also that the indentation style used by QXmlFormatter remains loosely defined and may change in future versions of Qt. 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.

   QXmlQuery query = new QXmlQuery();
   query.setQuery("doc('index.html')/html/body/p[1]");

   QXmlFormatterPointer formatter(new QXmlFormatter(query, myOutputDevice));
   formatter.setIndentationDepth(2);
   query.evaluateToReceiver(formatter);


Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QXmlFormatter(QXmlQuery query, QIODevice outputDevice)
           Constructs a formatter that uses the name pool and message handler in query, and writes the result to outputDevice as formatted XML.
 
Method Summary
 int indentationDepth()
          Returns the number of spaces QXmlFormatter will output for each indentation level.
 void setIndentationDepth(int depth)
          Sets depth to be the number of spaces QXmlFormatter will output for level of indentation.
 
Methods inherited from class com.trolltech.qt.xmlpatterns.QXmlSerializer
codec, outputDevice, setCodec
 
Methods inherited from class com.trolltech.qt.xmlpatterns.QAbstractXmlReceiver
atomicValue, attribute, characters, clone, comment, endDocument, endElement, endOfSequence, namespaceBinding, processingInstruction, startDocument, startElement, startOfSequence, whitespaceOnly
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QXmlFormatter

public QXmlFormatter(QXmlQuery query,
                     QIODevice outputDevice)
Constructs a formatter that uses the name pool and message handler in query, and writes the result to outputDevice as formatted XML.

outputDevice is passed directly to QXmlSerializer's constructor.

See also:
QXmlSerializer.

Method Detail

indentationDepth

public final int indentationDepth()
Returns the number of spaces QXmlFormatter will output for each indentation level. The default is four.

See also:
setIndentationDepth().


setIndentationDepth

public final void setIndentationDepth(int depth)
Sets depth to be the number of spaces QXmlFormatter will output for level of indentation. The default is four.

See also:
indentationDepth().