|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.xmlpatterns.QAbstractXmlReceiver
com.trolltech.qt.xmlpatterns.QXmlSerializer
com.trolltech.qt.xmlpatterns.QXmlFormatter
public class QXmlFormatter
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: QXmlFormatter outputs this: 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.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
| 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 | |
|---|---|
static QXmlFormatter |
fromNativePointer(QNativePointer nativePointer)
|
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 |
|---|
clone, comment, endDocument, endElement, namespaceBinding, nativePointerArray, processingInstruction, startDocument, startElement, 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 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 |
|---|
public QXmlFormatter(QXmlQuery query,
QIODevice outputDevice)
outputDevice is passed directly to QXmlSerializer's constructor.
QXmlSerializer.
| Method Detail |
|---|
public final int indentationDepth()
QXmlFormatter will output for each indentation level. The default is four. setIndentationDepth().
public final void setIndentationDepth(int depth)
QXmlFormatter will output for level of indentation. The default is four. indentationDepth().
public static QXmlFormatter fromNativePointer(QNativePointer nativePointer)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||