Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtCore.QXmlStreamWriter Class Reference

The QXmlStreamWriter class provides an XML writer with a simple streaming API. More...

Inheritance diagram for QtCore.QXmlStreamWriter:
Collaboration diagram for QtCore.QXmlStreamWriter:

Public Member Functions

 QXmlStreamWriter ()
 
 
 QXmlStreamWriter (QIODevice device)
 
 
 QXmlStreamWriter (QByteArray array)
 
 
 QXmlStreamWriter (System.Text.StringBuilder @string)
 
 
virtual void CreateProxy ()
 
new bool HasError ()
 
 
new void SetCodec (string codecName)
 
 
new void WriteAttribute (QXmlStreamAttribute attribute)
 
 
new void WriteAttribute (string qualifiedName, string value)
 
 
new void WriteAttribute (string namespaceUri, string name, string value)
 
 
new void WriteAttributes (QXmlStreamAttributes attributes)
 
 
new void WriteCDATA (string text)
 
 
new void WriteCharacters (string text)
 
 
new void WriteComment (string text)
 
 
new void WriteCurrentToken (QXmlStreamReader reader)
 
 
new void WriteDTD (string dtd)
 
 
new void WriteDefaultNamespace (string namespaceUri)
 
 
new void WriteEmptyElement (string qualifiedName)
 
 
new void WriteEmptyElement (string namespaceUri, string name)
 
 
new void WriteEndDocument ()
 
 
new void WriteEndElement ()
 
 
new void WriteEntityReference (string name)
 
 
new void WriteNamespace (string namespaceUri, string prefix="")
 
 
new void WriteProcessingInstruction (string target, string data="")
 
 
new void WriteStartDocument ()
 
 
new void WriteStartDocument (string version)
 
 
new void WriteStartDocument (string version, bool standalone)
 
 
new void WriteStartElement (string qualifiedName)
 
 
new void WriteStartElement (string namespaceUri, string name)
 
 
new void WriteTextElement (string qualifiedName, string text)
 
 
new void WriteTextElement (string namespaceUri, string name, string text)
 
 
new void Dispose ()
 

Protected Member Functions

 QXmlStreamWriter (System.Type dummy)
 

Protected Attributes

SmokeInvocation interceptor
 

Properties

new bool AutoFormatting [get, set]
 
new int AutoFormattingIndent [get, set]
 
new QTextCodec Codec [get, set]
 
 
new QIODevice Device [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 

Detailed Description

The QXmlStreamWriter class provides an XML writer with a simple streaming API.

QXmlStreamWriter is the counterpart to QXmlStreamReader for writing XML. Like its related class, it operates on a QIODevice specified with setDevice(). The API is simple and straightforward: 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.

The following abridged code snippet shows the basic use of the class to write formatted XML with indentation:

QXmlStreamWriter stream(&output);

stream.setAutoFormatting(true);

stream.writeStartDocument();

...

stream.writeStartElement("bookmark");

stream.writeAttribute("href", "http://qt.nokia.com/");

stream.writeTextElement("title", "Qt Home");

stream.writeEndElement(); // bookmark

...

stream.writeEndDocument();

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().

If an error occurs while writing to the underlying device, hasError() starts returning true and subsequent writes are ignored.

The QXmlStream Bookmarks Example illustrates how to use a stream writer to write an XML bookmark file (XBEL) that was previously read in by a QXmlStreamReader.

Constructor & Destructor Documentation

QtCore.QXmlStreamWriter.QXmlStreamWriter ( System.Type  dummy)
protected
QtCore.QXmlStreamWriter.QXmlStreamWriter ( )

Constructs a stream writer.

See also setDevice().

QtCore.QXmlStreamWriter.QXmlStreamWriter ( QIODevice  device)

Constructs a stream writer that writes into device;

QtCore.QXmlStreamWriter.QXmlStreamWriter ( QByteArray  array)

Constructs a stream writer that writes into array. This is the same as creating an xml writer that operates on a QBuffer device which in turn operates on array.

QtCore.QXmlStreamWriter.QXmlStreamWriter ( System.Text.StringBuilder @  string)

Constructs a stream writer that writes into string.

Member Function Documentation

virtual void QtCore.QXmlStreamWriter.CreateProxy ( )
virtual
new void QtCore.QXmlStreamWriter.Dispose ( )
new bool QtCore.QXmlStreamWriter.HasError ( )

Returns true if the stream failed to write to the underlying device; otherwise returns false.

The error status is never reset. Writes happening after the error occurred are ignored, even if the error condition is cleared.

This function was introduced in Qt 4.8.

new void QtCore.QXmlStreamWriter.SetCodec ( string  codecName)

Sets the codec for this stream to the QTextCodec for the encoding specified by codecName. Common values for codecName include "ISO 8859-1", "UTF-8", and "UTF-16". If the encoding isn't recognized, nothing happens.

See also QTextCodec::codecForName().

new void QtCore.QXmlStreamWriter.WriteAttribute ( QXmlStreamAttribute  attribute)

This is an overloaded function.

Writes the attribute.

This function can only be called after writeStartElement() before any content is written, or after writeEmptyElement().

new void QtCore.QXmlStreamWriter.WriteAttribute ( string  qualifiedName,
string  value 
)

This is an overloaded function.

Writes an attribute with qualifiedName and value.

This function can only be called after writeStartElement() before any content is written, or after writeEmptyElement().

new void QtCore.QXmlStreamWriter.WriteAttribute ( string  namespaceUri,
string  name,
string  value 
)

Writes an attribute with name and value, prefixed for the specified namespaceUri. If the namespace has not been declared yet, QXmlStreamWriter will generate a namespace declaration for it.

This function can only be called after writeStartElement() before any content is written, or after writeEmptyElement().

new void QtCore.QXmlStreamWriter.WriteAttributes ( QXmlStreamAttributes  attributes)

Writes the attribute vector attributes. If a namespace referenced in an attribute not been declared yet, QXmlStreamWriter will generate a namespace declaration for it.

This function can only be called after writeStartElement() before any content is written, or after writeEmptyElement().

See also writeAttribute() and writeNamespace().

new void QtCore.QXmlStreamWriter.WriteCDATA ( string  text)

Writes text as CDATA section. If text contains the forbidden character sequence "]]>", it is split into different CDATA sections.

This function mainly exists for completeness. Normally you should not need use it, because writeCharacters() automatically escapes all non-content characters.

new void QtCore.QXmlStreamWriter.WriteCharacters ( string  text)

Writes text. The characters "<", "&", and """ are escaped as entity references "&lt;", "&amp;, and "&quot;". To avoid the forbidden sequence "]]>", ">" is also escaped as "&gt;".

See also writeEntityReference().

new void QtCore.QXmlStreamWriter.WriteComment ( string  text)

Writes text as XML comment, where text must not contain the forbidden sequence "–" or end with "-". Note that XML does not provide any way to escape "-" in a comment.

new void QtCore.QXmlStreamWriter.WriteCurrentToken ( QXmlStreamReader  reader)

Writes the current state of the reader. All possible valid states are supported.

The purpose of this function is to support chained processing of XML data.

See also QXmlStreamReader::tokenType().

new void QtCore.QXmlStreamWriter.WriteDefaultNamespace ( string  namespaceUri)

Writes a default namespace declaration for 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.

new void QtCore.QXmlStreamWriter.WriteDTD ( string  dtd)

Writes a DTD section. The dtd represents the entire doctypedecl production from the XML 1.0 specification.

new void QtCore.QXmlStreamWriter.WriteEmptyElement ( string  qualifiedName)

This is an overloaded function.

Writes an empty element with qualified name qualifiedName. Subsequent calls to writeAttribute() will add attributes to this element.

new void QtCore.QXmlStreamWriter.WriteEmptyElement ( string  namespaceUri,
string  name 
)

Writes an empty element with name, prefixed for the specified namespaceUri. If the namespace has not been declared, QXmlStreamWriter will generate a namespace declaration for it. Subsequent calls to writeAttribute() will add attributes to this element.

See also writeNamespace().

new void QtCore.QXmlStreamWriter.WriteEndDocument ( )

Closes all remaining open start elements and writes a newline.

See also writeStartDocument().

new void QtCore.QXmlStreamWriter.WriteEndElement ( )

Closes the previous start element.

See also writeStartElement().

new void QtCore.QXmlStreamWriter.WriteEntityReference ( string  name)

Writes the entity reference name to the stream, as "&name;".

new void QtCore.QXmlStreamWriter.WriteNamespace ( string  namespaceUri,
string  prefix = "" 
)

Writes a namespace declaration for namespaceUri with prefix. If prefix is empty, 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.

new void QtCore.QXmlStreamWriter.WriteProcessingInstruction ( string  target,
string  data = "" 
)

Writes an XML processing instruction with target and data, where data must not contain the sequence "?>".

new void QtCore.QXmlStreamWriter.WriteStartDocument ( )

This is an overloaded function.

Writes a document start with XML version number "1.0". This also writes the encoding information.

This function was introduced in Qt 4.5.

See also writeEndDocument() and setCodec().

new void QtCore.QXmlStreamWriter.WriteStartDocument ( string  version)

Writes a document start with the XML version number version.

See also writeEndDocument().

new void QtCore.QXmlStreamWriter.WriteStartDocument ( string  version,
bool  standalone 
)

Writes a document start with the XML version number version and a standalone attribute standalone.

This function was introduced in Qt 4.5.

See also writeEndDocument().

new void QtCore.QXmlStreamWriter.WriteStartElement ( string  qualifiedName)

This is an overloaded function.

Writes a start element with qualifiedName. Subsequent calls to writeAttribute() will add attributes to this element.

See also writeEndElement() and writeEmptyElement().

new void QtCore.QXmlStreamWriter.WriteStartElement ( string  namespaceUri,
string  name 
)

Writes a start element with name, prefixed for the specified namespaceUri. If the namespace has not been declared yet, QXmlStreamWriter will generate a namespace declaration for it. Subsequent calls to writeAttribute() will add attributes to this element.

See also writeNamespace(), writeEndElement(), and writeEmptyElement().

new void QtCore.QXmlStreamWriter.WriteTextElement ( string  qualifiedName,
string  text 
)

This is an overloaded function.

Writes a text element with qualifiedName and text.

This is a convenience function equivalent to:

writeStartElement(qualifiedName);

writeCharacters(text);

writeEndElement();

new void QtCore.QXmlStreamWriter.WriteTextElement ( string  namespaceUri,
string  name,
string  text 
)

Writes a text element with name, prefixed for the specified namespaceUri, and text. If the namespace has not been declared, QXmlStreamWriter will generate a namespace declaration for it.

This is a convenience function equivalent to:

writeStartElement(namespaceUri, name);

writeCharacters(text);

writeEndElement();

Member Data Documentation

SmokeInvocation QtCore.QXmlStreamWriter.interceptor
protected

Property Documentation

new bool QtCore.QXmlStreamWriter.AutoFormatting
getset
new int QtCore.QXmlStreamWriter.AutoFormattingIndent
getset
new QTextCodec QtCore.QXmlStreamWriter.Codec
getset

Returns the codec that is currently assigned to the stream.

Sets the codec for this stream to codec. The codec is used for encoding any data that is written. By default, QXmlStreamWriter uses UTF-8.

The encoding information is stored in the initial xml tag which gets written when you call writeStartDocument(). Call this function before calling writeStartDocument().

new QIODevice QtCore.QXmlStreamWriter.Device
getset

Returns the current device associated with the QXmlStreamWriter, or 0 if no device has been assigned.

Sets the current device to device. If you want the stream to write into a QByteArray, you can create a QBuffer device.

virtual System.IntPtr QtCore.QXmlStreamWriter.SmokeObject
getset