Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Table data into XML file format
Forum Updated to NodeBB v4.3 + New Features

Table data into XML file format

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 4.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hi

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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      [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.

      http://anavi.org/

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3

        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?

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Indrajeet
          wrote on last edited by
          #4

          Hi Zap

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

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            "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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved