Results 1 to 2 of 2

Thread: problem in creating xml file.

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: problem in creating xml file.

    Hi all
    I am creating a .xml file and write in it but the contents are not written to it. I am coding like this
    Qt Code:
    1. const int Indent = 4;
    2. QDomElement root = doc.createElement("doc");
    3. QDomElement quote = doc.createElement("quote");
    4. QDomElement translation = doc.createElement("translation");
    5. QDomText latin = doc.createTextNode("Ars longa vita brevis");
    6. QDomText english = doc.createTextNode("Art is long, life is short");
    7. doc.appendChild(root);
    8. root.appendChild(quote);
    9. root.appendChild(translation);
    10. quote.appendChild(latin);
    11. translation.appendChild(english);
    12. QFile *file = new QFile("E:\test.txt");
    13. if(!file->open(QIODevice::WriteOnly))
    14. qDebug()<<"error";
    15. QTextStream ts(file);
    16. QDomNode xmlNode = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"ISO-8859-1\"");
    17. doc.insertBefore(xmlNode, doc.firstChild());
    18. ts << doc.toString();
    19. doc.save(ts, Indent);
    20. file->close();
    To copy to clipboard, switch view to plain text mode 

    Please tell me what i am doing wrong, i am not able to view my file.
    Thanks for help.


    Added after 6 minutes:


    I solved the problem.
    Sorry.
    Last edited by Niamita; 6th September 2011 at 09:02.

  2. #2
    Join Date
    Sep 2011
    Location
    Ukraine, Kharkov
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in creating xml file.

    Can make better use of QXmlStreamWriter?

    Qt Code:
    1. QDomDocument doc("mydocument");
    2. QFile file("mydocument.xml");
    3. if (!file.open(QIODevice::ReadOnly))
    4. return;
    5. if (!doc.setContent(&file)) {
    6. file.close();
    7. return;
    8. }
    9. file.close();
    To copy to clipboard, switch view to plain text mode 
    It's example from help of QDomDocument class. You need to execute setContent.

Similar Threads

  1. Creating xml file from Xml Schema (xsd) file
    By pieczara in forum Newbie
    Replies: 1
    Last Post: 25th February 2011, 23:11
  2. Replies: 0
    Last Post: 17th December 2010, 16:38
  3. creating Xml file using QT
    By rk0747 in forum Qt Programming
    Replies: 3
    Last Post: 30th January 2010, 11:16
  4. Creating xls File
    By bismitapadhy in forum Qt Programming
    Replies: 0
    Last Post: 26th May 2009, 11:35
  5. Creating new XML file
    By Pembar in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2009, 08:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.