#include <QtGui>
/////#include "qzipreader_p.h"
//////#include "qzipwriter_p.h"
#include <QFileInfo>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
class DocumentWriter
{
public:
typedef enum
{
DOC_NOT_KNOW = 404,
DOC_XHTML = 100,
DOC_ODT = 200,
DOC_FOP = 300,
DOC_RTF = 400,
DOC_XML = 500,
DOC_PAGE = 600 /* binary */
} WDOCTYPE;
DocumentWriter
( const QString &fileName
) : de
(0),cod
(QTextCodec::codecForHtml("utf-8")),type
(DOC_FOP
) {
const QString ext
= fi.
completeSuffix().
toLower();
if (ext == "xml") {
type = DOC_XML;
} else if (ext == "html") {
type = DOC_XHTML;
} else if (ext == "odt") {
type = DOC_ODT;
}
qDebug() << "### file open ---------- " << fileName;
de = file;
}
ft = cod->name();
}
~DocumentWriter() {
de->close();
}
WDOCTYPE type;
};
int main( int argc, char ** argv )
{
DocumentWriter one("dummytest.xml");
QXmlStreamWriter writer(one.device());
writer.
setCodec(QTextCodec::codecForName("utf-8"));
writer.setAutoFormatting(true);
writer.setAutoFormattingIndent(2);
qDebug() << "### xml on codec init ---------- " << writer.codec()->name();
writer.
writeNamespace(fopNS,
QString::fromLatin1("fo"));
writer.
writeNamespace(svgNS,
QString::fromLatin1("svg"));
writer.
writeNamespace(xlinkNS,
QString::fromLatin1("uri"));
writer.
writeNamespace(cmsNS,
QString::fromLatin1("cms"));
writer.writeStartDocument();
writer.
writeStartElement(fopNS,
QString::fromLatin1("root"));
writer.
writeStartElement(fopNS,
QString::fromLatin1("flow"));
for (int i = 0; i < 10000; ++i) {
writer.
writeStartElement(fopNS,
QString::fromLatin1("block"));
writer.
writeAttribute(fopNS,
QString::fromLatin1("padding-top"),
QString("10"));
writer.
writeCharacters (QString("Line nummer %1").
arg(i
) );
writer.
writeStartElement(fopNS,
QString::fromLatin1("inline"));
/* append sub node to last elements */
QXmlStreamReader chidxml
(QString("<root><node>data</node></root>"));
////////while (!chidxml.atEnd()) {
if (!chidxml.hasError()) {
writer.writeCurrentToken(chidxml);
}
///////}
writer.writeEndElement();
writer.writeEndElement();
}
///////writer.writeEndElement();
///////writer.writeEndElement();
////////writer.writeEndElement();
///////////writer.writeEndElement();
qDebug() << "### xml on codec end ---------- " << writer.codec()->name();
writer.writeEndDocument();
t.setPlainText ( txtlog );
t.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
//////#include "main.moc"
#include <QtGui>
/////#include "qzipreader_p.h"
//////#include "qzipwriter_p.h"
#include <QFileInfo>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
class DocumentWriter
{
public:
typedef enum
{
DOC_NOT_KNOW = 404,
DOC_XHTML = 100,
DOC_ODT = 200,
DOC_FOP = 300,
DOC_RTF = 400,
DOC_XML = 500,
DOC_PAGE = 600 /* binary */
} WDOCTYPE;
DocumentWriter( const QString &fileName )
: de(0),cod(QTextCodec::codecForHtml("utf-8")),type(DOC_FOP)
{
QFileInfo fi(fileName);
const QString ext = fi.completeSuffix().toLower();
if (ext == "xml") {
type = DOC_XML;
} else if (ext == "html") {
type = DOC_XHTML;
} else if (ext == "odt") {
type = DOC_ODT;
}
QFile *file = new QFile(fileName);
if (file->open(QIODevice::WriteOnly)) {
qDebug() << "### file open ---------- " << fileName;
de = file;
}
ft = cod->name();
}
~DocumentWriter() {
de->close();
}
QIODevice *device() { return de; }
QByteArray format() { return ft; }
QTextCodec *codec() { return cod; }
QByteArray ft;
QIODevice *de;
QTextCodec *cod;
WDOCTYPE type;
};
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
QString txtlog;
DocumentWriter one("dummytest.xml");
QString fopNS (QLatin1String("http://www.w3.org/1999/XSL/Format"));
QString svgNS (QLatin1String("http://www.w3.org/2000/svg"));
QString xlinkNS (QLatin1String("http://www.w3.org/1999/xlink"));
QString cmsNS (QLatin1String("http://www.pulitzer.ch/2007/CMSFormat"));
QXmlStreamWriter writer(one.device());
writer.setCodec(QTextCodec::codecForName("utf-8"));
writer.setAutoFormatting(true);
writer.setAutoFormattingIndent(2);
qDebug() << "### xml on codec init ---------- " << writer.codec()->name();
writer.writeNamespace(fopNS, QString::fromLatin1("fo"));
writer.writeNamespace(svgNS, QString::fromLatin1("svg"));
writer.writeNamespace(xlinkNS, QString::fromLatin1("uri"));
writer.writeNamespace(cmsNS, QString::fromLatin1("cms"));
writer.writeStartDocument();
writer.writeStartElement(fopNS, QString::fromLatin1("root"));
writer.writeStartElement(fopNS, QString::fromLatin1("flow"));
for (int i = 0; i < 10000; ++i) {
writer.writeStartElement(fopNS, QString::fromLatin1("block"));
writer.writeAttribute(fopNS, QString::fromLatin1("padding-top"),QString("10"));
writer.writeCharacters (QString("Line nummer %1").arg(i) );
writer.writeStartElement(fopNS, QString::fromLatin1("inline"));
/* append sub node to last elements */
QXmlStreamReader chidxml(QString("<root><node>data</node></root>"));
////////while (!chidxml.atEnd()) {
if (!chidxml.hasError()) {
writer.writeCurrentToken(chidxml);
}
///////}
writer.writeEndElement();
writer.writeEndElement();
}
///////writer.writeEndElement();
///////writer.writeEndElement();
////////writer.writeEndElement();
///////////writer.writeEndElement();
qDebug() << "### xml on codec end ---------- " << writer.codec()->name();
writer.writeEndDocument();
QTextEdit t;
t.setPlainText ( txtlog );
t.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
//////#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks