:: printable version ::

XML writer class

::description ::changelog ::requirements ::features ::usage ::

Description

The Qt XML Module allows to easily read and parse XML documents, but it does not allow writing of XML. This class helps you create XML files with ease.

Changelog

Requirements

Features

Missing features and restrictions

::top::

Usage example

Here is a little XML document example:

<?xml version="1.0" encoding="UTF-8"?> <sample_document version="1.0"> <info> <visibility hidden="true"/> <user id="504" type="default"/> <data>Here comes some interesting text</data> </info> <info> <visibility hidden="false"/> <user id="550" type="default"/> <data>Some more text</data> </info> </sample_document>

And here is the code to write this XML snippet. It seems too long, right? It's just a trivial example; bear that you will call the XML writer from some sort of loop or method most of the time :)

#include <QFile> #include <QTextCodec> #include <QHash> #include "xmlwriter.h"
// ...
QFile file("myFile.xml"); if (!file.open(QIODevice::WriteOnly)) {
// ERROR
}
// Default text encoding: UTF-8
XmlWriter xout(&file);
// A hash is used to add attributes
QHash<QString,QString> attrs; attrs.insert("version", "1.0"); xout.writeOpenTag("sample_document", attrs); attrs.clear(); xout.writeOpenTag("info"); attrs.insert("hidden", "true"); xout.writeAtomTag("visibility", attrs); attrs.clear(); attrs.insert("id", "540"); attrs.insert("type", "default"); xout.writeAtomTag("user", attrs); attrs.clear(); xout.writeTaggedString("data", "Here comes some interesting text"); xout.writeCloseTag("info"); xout.writeOpenTag("info"); attrs.insert("hidden", "false"); xout.writeAtomTag("visibility", attrs); attrs.clear(); attrs.insert("id", "550"); attrs.insert("type", "default"); xout.writeAtomTag("user", attrs); attrs.clear(); xout.writeTaggedString("data", "Some more text"); xout.writeCloseTag("info"); xout.writeCloseTag("sample_document");
:: index :: top ::