View Full Version : Creating new XML file

15th May 2009, 12:13
Hey guys, I have the following code:

void xmlBaseTest::myBlankFile()
QFile data("booklist.xml");
QDomElement root = doc->createElement("booklist");

if (data.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream out(&data);

It creates the file:

<!DOCTYPE serverlist>

The line <booklist/> is causing problems, when trying to read it later using .setContent. I was wondering if there was any way to get it to print out <booklist></booklist> instead?

Thanks much

15th May 2009, 23:29
It can't be causing problems, it's perfectly valid. What exactly are the "problems"?

16th May 2009, 01:26
I have an other question about "valid XML":
is it possible to create a header line
<?xml version=\"1.0\" encoding=\"iso8859-1\" ?>"
by some calls of whatever or do I have to set them with

DomDocumentType doctype = impl.createDocumentType("name", QString::null, QString::null);
QDomDocument doc = impl.createDocument("uri", "name", doctype);
doc.setContent(QString("<?xml version=\"1.0\" encoding=\"iso8859-1\" ?>"));

Sorry, this piece of code is from Qt3. Until now I did not face the differences of XML code in Qt4.

16th May 2009, 09:06
<?xml version=\"1.0\" encoding=\"iso8859-1\" ?>"

QDomDocument doc("RootElement");
QDomProcessingInstruction process = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"iso8859-1\"");