|
|||||||||
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.xml.QXmlStreamWriter
public class QXmlStreamWriter
The QXmlStreamWriter
class provides an XML writer with a simple streaming API. QXmlStreamWriter
is the pendent to QXmlStreamReader
for writing XML. Like its related class, it operates on a QIODevice
specified with setDevice()
. The API is simple and straight forward: For every XML token or event you want to write, the writer provides a specialized function.
You start a document with writeStartDocument()
and end it with writeEndDocument()
. This will implicitly close all remaining open tags.
Element tags are opened with writeStartElement()
followed by writeAttribute()
or writeAttributes()
, element content, and then writeEndElement()
. A shorter form writeEmptyElement()
can be used to write empty elements, followed by writeAttributes()
.
Element content consists of either characters, entity references or nested elements. It is written with writeCharacters()
, which also takes care of escaping all forbidden characters and character sequences, writeEntityReference()
, or subsequent calls to writeStartElement()
. A convenience method writeTextElement()
can be used for writing terminal elements that contain nothing but text.
QXmlStreamWriter
takes care of prefixing namespaces, all you have to do is specify the namespaceUri when writing elements or attributes. If you must conform to certain prefixes, you can force the writer to use them by declaring the namespaces manually with either writeNamespace()
or writeDefaultNamespace()
. Alternatively, you can bypass the stream writer's namespace support and use overloaded methods that take a qualified name instead. The namespace http://www.w3.org/XML/1998/namespace is implicit and mapped to the prefix xml.
The stream writer can automatically format the generated XML data by adding line-breaks and indentation to empty sections between elements, making the XML data more readable for humans and easier to work with for most source code management systems. The feature can be turned on with the autoFormatting
property, and customized with the autoFormattingIndent
property.
Other functions are writeCDATA()
, writeComment()
, writeProcessingInstruction()
, and writeDTD()
. Chaining of XML streams is supported with writeCurrentToken()
.
By default, QXmlStreamWriter
encodes XML in UTF-8. Different encodings can be enforced using setCodec()
.
The QXmlStream Bookmarks Example illustrates how to use a subclassed stream writer to write an XML bookmark file (XBEL) that was previously read in by a QXmlStreamReader
.
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 | |
---|---|
QXmlStreamWriter()
Constructs a stream writer. |
|
QXmlStreamWriter(QByteArray array)
Constructs a stream writer that writes into array. |
|
QXmlStreamWriter(QIODevice device)
Constructs a stream writer that writes into device; |
Method Summary | |
---|---|
boolean |
autoFormatting()
the auto-formatting flag of the stream writer |
int |
autoFormattingIndent()
This property holds the number of spaces used for indentation when auto-formatting is enabled. |
QTextCodec |
codec()
Returns the codec that is currently assigned to the stream. |
QIODevice |
device()
Returns the current device associated with the QXmlStreamWriter , or 0 if no device has been assigned. |
static QXmlStreamWriter |
fromNativePointer(QNativePointer nativePointer)
|
void |
setAutoFormatting(boolean arg__1)
the auto-formatting flag of the stream writer |
void |
setAutoFormattingIndent(int spaces)
This property holds the number of spaces used for indentation when auto-formatting is enabled. |
void |
setCodec(QTextCodec codec)
Sets the codec for this stream to codec. |
void |
setCodec(java.lang.String codecName)
Sets the codec for this stream to the QTextCodec for the encoding specified by codecName. |
void |
setDevice(QIODevice device)
Sets the current device to device. |
void |
writeAttribute(QXmlStreamAttribute attribute)
Writes the attribute. |
void |
writeAttribute(java.lang.String qualifiedName,
java.lang.String value)
Writes an attribute with qualifiedName and value. |
void |
writeAttribute(java.lang.String namespaceUri,
java.lang.String name,
java.lang.String value)
Writes an attribute with name and value, prefixed for the specified namespaceUri. |
void |
writeAttributes(QXmlStreamAttributes attributes)
Writes the attribute vector attributes. |
void |
writeCDATA(java.lang.String text)
Writes text as CDATA section. |
void |
writeCharacters(java.lang.String text)
Writes text. |
void |
writeComment(java.lang.String text)
Writes text as XML comment, where text must not contain the forbidden sequence "--" or end with "-". |
void |
writeCurrentToken(QXmlStreamReader reader)
Writes the current state of the reader. |
void |
writeDefaultNamespace(java.lang.String namespaceUri)
Writes a default namespace declaration for namespaceUri. |
void |
writeDTD(java.lang.String dtd)
Writes a DTD section. |
void |
writeEmptyElement(java.lang.String qualifiedName)
Writes an empty element with qualified name qualifiedName. |
void |
writeEmptyElement(java.lang.String namespaceUri,
java.lang.String name)
Writes an empty element with name, prefixed for the specified namespaceUri. |
void |
writeEndDocument()
Closes all remaining open start elements and writes a newline. |
void |
writeEndElement()
Closes the previous start element. |
void |
writeEntityReference(java.lang.String name)
Writes the entity reference name to the stream, as "&name;". |
void |
writeNamespace(java.lang.String namespaceUri)
Writes a namespace declaration for namespaceUri with prefix. |
void |
writeNamespace(java.lang.String namespaceUri,
java.lang.String prefix)
Writes a namespace declaration for namespaceUri with prefix. |
void |
writeProcessingInstruction(java.lang.String target)
Writes an XML processing instruction with target and data, where data must not contain the sequence "?>". |
void |
writeProcessingInstruction(java.lang.String target,
java.lang.String data)
Writes an XML processing instruction with target and data, where data must not contain the sequence "?>". |
void |
writeStartDocument()
Writes a document start with XML version number "1.0" |
void |
writeStartDocument(java.lang.String version)
Writes a document start with the XML version number version. |
void |
writeStartElement(java.lang.String qualifiedName)
Writes a start element with qualifiedName. |
void |
writeStartElement(java.lang.String namespaceUri,
java.lang.String name)
Writes a start element with name, prefixed for the specified namespaceUri. |
void |
writeTextElement(java.lang.String qualifiedName,
java.lang.String text)
Writes a text element with qualifiedName and text. |
void |
writeTextElement(java.lang.String namespaceUri,
java.lang.String name,
java.lang.String text)
Writes a text element with name, prefixed for the specified namespaceUri, and text. |
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 |
---|
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QXmlStreamWriter()
setDevice()
.
public QXmlStreamWriter(QIODevice device)
public QXmlStreamWriter(QByteArray array)
Method Detail |
---|
public final boolean autoFormatting()
This property controls whether or not the stream writer automatically formats the generated XML data. If enabled, the writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace). The main purpose of auto-formatting is to split the data into several lines, and to increase readability for a human reader. The indentation depth can be controlled through the autoFormattingIndent
property.
By default, auto-formatting is disabled.
public final int autoFormattingIndent()
autoFormatting
.
public final QTextCodec codec()
setCodec()
.
public final QIODevice device()
QXmlStreamWriter
, or 0 if no device has been assigned. setDevice()
.
public final void setAutoFormatting(boolean arg__1)
This property controls whether or not the stream writer automatically formats the generated XML data. If enabled, the writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace). The main purpose of auto-formatting is to split the data into several lines, and to increase readability for a human reader. The indentation depth can be controlled through the autoFormattingIndent
property.
By default, auto-formatting is disabled.
public final void setAutoFormattingIndent(int spaces)
autoFormatting
.
public final void setCodec(QTextCodec codec)
QXmlStreamWriter
uses UTF-8. codec()
.
public final void setDevice(QIODevice device)
QByteArray
, you can create a QBuffer
device. device()
.
public final void writeAttribute(java.lang.String namespaceUri, java.lang.String name, java.lang.String value)
QXmlStreamWriter
will generate a namespace declaration for it. This function can only be called after writeStartElement()
before any content is written, or after writeEmptyElement()
.
public final void writeAttribute(java.lang.String qualifiedName, java.lang.String value)
This function can only be called after writeStartElement()
before any content is written, or after writeEmptyElement()
.
public final void writeAttribute(QXmlStreamAttribute attribute)
This function can only be called after writeStartElement()
before any content is written, or after writeEmptyElement()
.
public final void writeAttributes(QXmlStreamAttributes attributes)
QXmlStreamWriter
will generate a namespace declaration for it. This function can only be called after writeStartElement()
before any content is written, or after writeEmptyElement()
.
writeAttribute()
, and writeNamespace()
.
public final void writeCDATA(java.lang.String text)
This function mainly exists for completeness. Normally you should not need use it, because writeCharacters()
automatically escapes all non-content characters.
public final void writeCharacters(java.lang.String text)
writeEntityReference()
.
public final void writeComment(java.lang.String text)
public final void writeCurrentToken(QXmlStreamReader reader)
The purpose of this function is to support chained processing of XML data.
QXmlStreamReader::tokenType()
.
public final void writeDTD(java.lang.String dtd)
public final void writeDefaultNamespace(java.lang.String namespaceUri)
If writeStartElement()
or writeEmptyElement()
was called, the declaration applies to the current element; otherwise it applies to the next child element.
Note that the namespaces http://www.w3.org/XML/1998/namespace (bound to xmlns) and http://www.w3.org/2000/xmlns/ (bound to xml) by definition cannot be declared as default.
public final void writeEmptyElement(java.lang.String namespaceUri, java.lang.String name)
QXmlStreamWriter
will generate a namespace declaration for it. Subsequent calls to writeAttribute()
will add attributes to this element. writeNamespace()
.
public final void writeEmptyElement(java.lang.String qualifiedName)
writeAttribute()
will add attributes to this element.
public final void writeEndDocument()
writeStartDocument()
.
public final void writeEndElement()
writeStartElement()
.
public final void writeEntityReference(java.lang.String name)
public final void writeNamespace(java.lang.String namespaceUri)
QXmlStreamWriter
assigns a unique prefix consisting of the letter 'n' followed by a number. If writeStartElement()
or writeEmptyElement()
was called, the declaration applies to the current element; otherwise it applies to the next child element.
Note that the prefix xml is both predefined and reserved for http://www.w3.org/XML/1998/namespace, which in turn cannot be bound to any other prefix. The prefix xmlns and its URI http://www.w3.org/2000/xmlns/ are used for the namespace mechanism itself and thus completely forbidden in declarations.
public final void writeNamespace(java.lang.String namespaceUri, java.lang.String prefix)
QXmlStreamWriter
assigns a unique prefix consisting of the letter 'n' followed by a number. If writeStartElement()
or writeEmptyElement()
was called, the declaration applies to the current element; otherwise it applies to the next child element.
Note that the prefix xml is both predefined and reserved for http://www.w3.org/XML/1998/namespace, which in turn cannot be bound to any other prefix. The prefix xmlns and its URI http://www.w3.org/2000/xmlns/ are used for the namespace mechanism itself and thus completely forbidden in declarations.
public final void writeProcessingInstruction(java.lang.String target)
public final void writeProcessingInstruction(java.lang.String target, java.lang.String data)
public final void writeStartDocument()
writeEndDocument()
.
public final void writeStartDocument(java.lang.String version)
writeEndDocument()
.
public final void writeStartElement(java.lang.String namespaceUri, java.lang.String name)
QXmlStreamWriter
will generate a namespace declaration for it. Subsequent calls to writeAttribute()
will add attributes to this element. writeNamespace()
, writeEndElement()
, and writeEmptyElement()
.
public final void writeStartElement(java.lang.String qualifiedName)
writeAttribute()
will add attributes to this element. writeEndElement()
, and writeEmptyElement()
.
public final void writeTextElement(java.lang.String namespaceUri, java.lang.String name, java.lang.String text)
QXmlStreamWriter
will generate a namespace declaration for it. This is a convenience function equivalent to:
writeStartElement(namespaceUri, name); writeCharacters(text); writeEndElement();
public final void writeTextElement(java.lang.String qualifiedName, java.lang.String text)
This is a convenience function equivalent to:
writeStartElement(qualifiedName); writeCharacters(text); writeEndElement();
public static QXmlStreamWriter fromNativePointer(QNativePointer nativePointer)
public final void setCodec(java.lang.String codecName)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |