Table data into XML file format



  • Hi

    can anyone show me how to add table data into XML file format.



  • [quote author="Rajveer" date="1311055350"]can anyone show me how to add table data into XML file format.[/quote]

    You can use class "QDomDocument":http://doc.qt.nokia.com/latest/qdomdocument.html which represents an XML document and has methods for adding elements and attributes.



  • Your question is very generic. Can you be a little more specific and maybe give an example of the starting data format and what sort fo format you wish to end up with please?



  • Hi Zap

    QString data from each cell of table.
    Where the columns name will represent the XML tagname.



  • "QXmlStreamWriter":http://doc.qt.nokia.com/latest/qxmlstreamwriter.html is what you are looking for. No need for a full blown DOM (like QDomDocument) just for data serialization / deserialization (would add processing and memory overhead, would add dependency to QtXml).

    @
    QFile xmlFile("table.xml");

    xmlFile.open(QIODevice::WriteOnly | QIODevice::Truncate);

    QXmlStreamWriter xmlStreamWriter(&file;);

    xmlStreamWriter.writeStartDocument("1.0");
    foreach(RowType row, table.rows)
    {
    xmlStreamWriter.writeStartElement("row");
    foreach(ColumnType column, row.columns)
    {
    xmlStreamWriter.writeTextElement(namespaceUri, column.name, column.value);
    }
    xmlStreamWriter.writeEndElement();
    }
    xmlStreamWriter.writeEndDocument();

    xmlFile.close();
    @

    Brain to terminal. Not tested.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.