Originally Posted by
sattu
So, if i keep reading the database progressively and then send over the socket, then I think i would need to have many "MyParent" nodes instead of just one. I am not sure though because I have never used "QXmlStreamWriter" class.
You can achieve the result you want with QXmlStreamWriter:
1. Initialize the document with
streamWriter.writeStartDocument();
streamWriter.
writeStartElement(QString::fromAscii("MyParent"));
streamWriter.writeStartDocument();
streamWriter.writeStartElement(QString::fromAscii("MyParent"));
To copy to clipboard, switch view to plain text mode
2. Each time you want to add a record, do
streamWriter.
writeStartElement(QString::fromAscii("record"));
streamWriter.
writeTextElement(QString::fromAscii("UserID"),
QString::number(theUserID
));
streamWriter.
writeTextElement(QString::fromAscii("UserName"), theUserName
);
streamWriter.
writeTextElement(QString::fromAscii("UserType"), theUserType
);
streamWriter.writeEndElement();
streamWriter.writeStartElement(QString::fromAscii("record"));
streamWriter.writeTextElement(QString::fromAscii("UserID"), QString::number(theUserID));
streamWriter.writeTextElement(QString::fromAscii("UserName"), theUserName);
streamWriter.writeTextElement(QString::fromAscii("UserType"), theUserType);
streamWriter.writeEndElement();
To copy to clipboard, switch view to plain text mode
3. When you have written all the records, do
streamWriter.writeEndElement();
streamWriter.writeEndDocument();
streamWriter.writeEndElement();
streamWriter.writeEndDocument();
To copy to clipboard, switch view to plain text mode
Have a look at QXmlStreamWriter's api to see how you can choose the codec and auto formatting options (line breaks, indentation). What you need to do is monitor bytesWritten() and bytesToWrite() on the QTcpSocket to gradually process the records. Use an iterator (or the equivalent for the data structure you are using) to keep track of the next record to process.
Originally Posted by
sattu
What do you say?
I would not do that as it builds a huge data structure in memory when you can easily generate it on-the-fly with QXmlStreamWriter as explained above.
Bookmarks