#[repr(C)]
pub struct QXmlStreamWriter { /* private fields */ }
Expand description

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

C++ class: QXmlStreamWriter.

C++ documentation:

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-project.org/”); stream.writeTextElement(“title”, “Qt Project”); 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.

Implementations§

source§

impl QXmlStreamWriter

source

pub unsafe fn auto_formatting(&self) -> bool

The auto-formatting flag of the stream writer

Calls C++ function: bool QXmlStreamWriter::autoFormatting() const.

C++ documentation:

The auto-formatting flag of the stream writer

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.

This property was introduced in Qt 4.4.

Access functions:

bool autoFormatting() const
void setAutoFormatting(bool enable)
source

pub unsafe fn auto_formatting_indent(&self) -> c_int

This property holds the number of spaces or tabs used for indentation when auto-formatting is enabled. Positive numbers indicate spaces, negative numbers tabs.

Calls C++ function: int QXmlStreamWriter::autoFormattingIndent() const.

C++ documentation:

This property holds the number of spaces or tabs used for indentation when auto-formatting is enabled. Positive numbers indicate spaces, negative numbers tabs.

The default indentation is 4.

This property was introduced in Qt 4.4.

Access functions:

int autoFormattingIndent() const
void setAutoFormattingIndent(int spacesOrTabs)

See also autoFormatting.

source

pub unsafe fn codec(&self) -> Ptr<QTextCodec>

Returns the codec that is currently assigned to the stream.

Calls C++ function: QTextCodec* QXmlStreamWriter::codec() const.

C++ documentation:

Returns the codec that is currently assigned to the stream.

See also setCodec().

source

pub unsafe fn device(&self) -> QPtr<QIODevice>

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

Calls C++ function: QIODevice* QXmlStreamWriter::device() const.

C++ documentation:

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

See also setDevice().

source

pub unsafe fn has_error(&self) -> bool

Returns true if the stream failed to write to the underlying device.

Calls C++ function: bool QXmlStreamWriter::hasError() const.

C++ documentation:

Returns true if the stream failed to write to the underlying device.

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

source

pub unsafe fn new() -> CppBox<QXmlStreamWriter>

Constructs a stream writer.

Calls C++ function: [constructor] void QXmlStreamWriter::QXmlStreamWriter().

C++ documentation:

Constructs a stream writer.

See also setDevice().

source

pub unsafe fn from_q_io_device( device: impl CastInto<Ptr<QIODevice>> ) -> CppBox<QXmlStreamWriter>

Constructs a stream writer that writes into device;

Calls C++ function: [constructor] void QXmlStreamWriter::QXmlStreamWriter(QIODevice* device).

C++ documentation:

Constructs a stream writer that writes into device;

source

pub unsafe fn from_q_byte_array( array: impl CastInto<Ptr<QByteArray>> ) -> CppBox<QXmlStreamWriter>

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.

Calls C++ function: [constructor] void QXmlStreamWriter::QXmlStreamWriter(QByteArray* array).

C++ documentation:

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.

source

pub unsafe fn from_q_string( string: impl CastInto<Ptr<QString>> ) -> CppBox<QXmlStreamWriter>

Constructs a stream writer that writes into string.

Calls C++ function: [constructor] void QXmlStreamWriter::QXmlStreamWriter(QString* string).

C++ documentation:

Constructs a stream writer that writes into string.

source

pub unsafe fn set_auto_formatting(&self, arg1: bool)

Enables auto formatting if enable is true, otherwise disables it.

Calls C++ function: void QXmlStreamWriter::setAutoFormatting(bool arg1).

C++ documentation:

Enables auto formatting if enable is true, otherwise disables it.

The default value is false.

This function was introduced in Qt 4.4.

Note: Setter function for property autoFormatting.

See also autoFormatting().

source

pub unsafe fn set_auto_formatting_indent(&self, spaces_or_tabs: c_int)

This property holds the number of spaces or tabs used for indentation when auto-formatting is enabled. Positive numbers indicate spaces, negative numbers tabs.

Calls C++ function: void QXmlStreamWriter::setAutoFormattingIndent(int spacesOrTabs).

C++ documentation:

This property holds the number of spaces or tabs used for indentation when auto-formatting is enabled. Positive numbers indicate spaces, negative numbers tabs.

The default indentation is 4.

This property was introduced in Qt 4.4.

Access functions:

int autoFormattingIndent() const
void setAutoFormattingIndent(int spacesOrTabs)

See also autoFormatting.

source

pub unsafe fn set_codec_q_text_codec( &self, codec: impl CastInto<Ptr<QTextCodec>> )

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.

Calls C++ function: void QXmlStreamWriter::setCodec(QTextCodec* codec).

C++ documentation:

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

See also codec().

source

pub unsafe fn set_codec_char(&self, codec_name: *const c_char)

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.

Calls C++ function: void QXmlStreamWriter::setCodec(const char* codecName).

C++ documentation:

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

source

pub unsafe fn set_device(&self, device: impl CastInto<Ptr<QIODevice>>)

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

Calls C++ function: void QXmlStreamWriter::setDevice(QIODevice* device).

C++ documentation:

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

See also device().

source

pub unsafe fn write_attribute_2a( &self, qualified_name: impl CastInto<Ref<QString>>, value: impl CastInto<Ref<QString>> )

This is an overloaded function.

Calls C++ function: void QXmlStreamWriter::writeAttribute(const QString& qualifiedName, const QString& value).

C++ documentation:

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

source

pub unsafe fn write_attribute_3a( &self, namespace_uri: impl CastInto<Ref<QString>>, name: impl CastInto<Ref<QString>>, value: impl CastInto<Ref<QString>> )

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.

Calls C++ function: void QXmlStreamWriter::writeAttribute(const QString& namespaceUri, const QString& name, const QString& value).

C++ documentation:

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

source

pub unsafe fn write_attribute_1a( &self, attribute: impl CastInto<Ref<QXmlStreamAttribute>> )

This is an overloaded function.

Calls C++ function: void QXmlStreamWriter::writeAttribute(const QXmlStreamAttribute& attribute).

C++ documentation:

This is an overloaded function.

Writes the attribute.

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

source

pub unsafe fn write_attributes( &self, attributes: impl CastInto<Ref<QXmlStreamAttributes>> )

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

Calls C++ function: void QXmlStreamWriter::writeAttributes(const QXmlStreamAttributes& attributes).

C++ documentation:

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

source

pub unsafe fn write_c_d_a_t_a(&self, text: impl CastInto<Ref<QString>>)

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

Calls C++ function: void QXmlStreamWriter::writeCDATA(const QString& text).

C++ documentation:

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.

source

pub unsafe fn write_characters(&self, text: impl CastInto<Ref<QString>>)

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

Calls C++ function: void QXmlStreamWriter::writeCharacters(const QString& text).

C++ documentation:

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

source

pub unsafe fn write_comment(&self, text: impl CastInto<Ref<QString>>)

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.

Calls C++ function: void QXmlStreamWriter::writeComment(const QString& text).

C++ documentation:

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.

source

pub unsafe fn write_current_token( &self, reader: impl CastInto<Ref<QXmlStreamReader>> )

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

Calls C++ function: void QXmlStreamWriter::writeCurrentToken(const QXmlStreamReader& reader).

C++ documentation:

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

source

pub unsafe fn write_d_t_d(&self, dtd: impl CastInto<Ref<QString>>)

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

Calls C++ function: void QXmlStreamWriter::writeDTD(const QString& dtd).

C++ documentation:

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

source

pub unsafe fn write_default_namespace( &self, namespace_uri: impl CastInto<Ref<QString>> )

Writes a default namespace declaration for namespaceUri.

Calls C++ function: void QXmlStreamWriter::writeDefaultNamespace(const QString& namespaceUri).

C++ documentation:

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.

source

pub unsafe fn write_empty_element_1a( &self, qualified_name: impl CastInto<Ref<QString>> )

This is an overloaded function.

Calls C++ function: void QXmlStreamWriter::writeEmptyElement(const QString& qualifiedName).

C++ documentation:

This is an overloaded function.

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

source

pub unsafe fn write_empty_element_2a( &self, namespace_uri: impl CastInto<Ref<QString>>, name: impl CastInto<Ref<QString>> )

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.

Calls C++ function: void QXmlStreamWriter::writeEmptyElement(const QString& namespaceUri, const QString& name).

C++ documentation:

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

source

pub unsafe fn write_end_document(&self)

Closes all remaining open start elements and writes a newline.

Calls C++ function: void QXmlStreamWriter::writeEndDocument().

C++ documentation:

Closes all remaining open start elements and writes a newline.

See also writeStartDocument().

source

pub unsafe fn write_end_element(&self)

Closes the previous start element.

Calls C++ function: void QXmlStreamWriter::writeEndElement().

C++ documentation:

Closes the previous start element.

See also writeStartElement().

source

pub unsafe fn write_entity_reference(&self, name: impl CastInto<Ref<QString>>)

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

Calls C++ function: void QXmlStreamWriter::writeEntityReference(const QString& name).

C++ documentation:

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

source

pub unsafe fn write_namespace_2a( &self, namespace_uri: impl CastInto<Ref<QString>>, prefix: impl CastInto<Ref<QString>> )

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.

Calls C++ function: void QXmlStreamWriter::writeNamespace(const QString& namespaceUri, const QString& prefix = …).

C++ documentation:

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.

source

pub unsafe fn write_namespace_1a( &self, namespace_uri: impl CastInto<Ref<QString>> )

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.

Calls C++ function: void QXmlStreamWriter::writeNamespace(const QString& namespaceUri).

C++ documentation:

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.

source

pub unsafe fn write_processing_instruction_2a( &self, target: impl CastInto<Ref<QString>>, data: impl CastInto<Ref<QString>> )

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

Calls C++ function: void QXmlStreamWriter::writeProcessingInstruction(const QString& target, const QString& data = …).

C++ documentation:

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

source

pub unsafe fn write_processing_instruction_1a( &self, target: impl CastInto<Ref<QString>> )

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

Calls C++ function: void QXmlStreamWriter::writeProcessingInstruction(const QString& target).

C++ documentation:

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

source

pub unsafe fn write_start_document_0a(&self)

This is an overloaded function.

Calls C++ function: void QXmlStreamWriter::writeStartDocument().

C++ documentation:

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

source

pub unsafe fn write_start_document_1a( &self, version: impl CastInto<Ref<QString>> )

Writes a document start with the XML version number version.

Calls C++ function: void QXmlStreamWriter::writeStartDocument(const QString& version).

C++ documentation:

Writes a document start with the XML version number version.

See also writeEndDocument().

source

pub unsafe fn write_start_document_2a( &self, version: impl CastInto<Ref<QString>>, standalone: bool )

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

Calls C++ function: void QXmlStreamWriter::writeStartDocument(const QString& version, bool standalone).

C++ documentation:

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

source

pub unsafe fn write_start_element_1a( &self, qualified_name: impl CastInto<Ref<QString>> )

This is an overloaded function.

Calls C++ function: void QXmlStreamWriter::writeStartElement(const QString& qualifiedName).

C++ documentation:

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

source

pub unsafe fn write_start_element_2a( &self, namespace_uri: impl CastInto<Ref<QString>>, name: impl CastInto<Ref<QString>> )

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.

Calls C++ function: void QXmlStreamWriter::writeStartElement(const QString& namespaceUri, const QString& name).

C++ documentation:

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

source

pub unsafe fn write_text_element_2a( &self, qualified_name: impl CastInto<Ref<QString>>, text: impl CastInto<Ref<QString>> )

This is an overloaded function.

Calls C++ function: void QXmlStreamWriter::writeTextElement(const QString& qualifiedName, const QString& text).

C++ documentation:

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

source

pub unsafe fn write_text_element_3a( &self, namespace_uri: impl CastInto<Ref<QString>>, name: impl CastInto<Ref<QString>>, text: impl CastInto<Ref<QString>> )

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.

Calls C++ function: void QXmlStreamWriter::writeTextElement(const QString& namespaceUri, const QString& name, const QString& text).

C++ documentation:

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

Trait Implementations§

source§

impl CppDeletable for QXmlStreamWriter

source§

unsafe fn delete(&self)

Destructor.

Calls C++ function: [destructor] void QXmlStreamWriter::~QXmlStreamWriter().

C++ documentation:

Destructor.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.