Results 1 to 3 of 3

Thread: XML Data displayed in one file

  1. #1
    Join Date
    Mar 2008
    Posts
    55
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    2

    Default XML Data displayed in one file

    Hello everbody,
    I'm développed an application which extract data from a database and save them in an XML file.
    Bonjour tout le monde, j'ai développé une application qui extrait des données depuis une base de données puis insère ces données dans un fichier XML à l'aide de QXmlStreamWriter.
    Qt Code:
    1. /*open a file */
    2. QFile file(QString("%1\\specialite.xml").arg(qApp->applicationDirPath()));
    3.  
    4. if (!file.open(QIODevice::OnlyWrite | QIODevice::Text))
    5. {
    6. /* show wrror message if not able to open file */
    7. QMessageBox::warning(0, "Read only", "The file is in read only mode");
    8. }
    9. else
    10. {
    11. QTextStream out(&file);
    12. out.setCodec("UTF-8");
    13.  
    14. int index = 1;
    15.  
    16. /*if file is successfully opened then create XML*/
    17. QXmlStreamWriter* xmlWriter = new QXmlStreamWriter();
    18.  
    19. /* set device (here file)to streamwriter */
    20. xmlWriter->setDevice(&file);
    21.  
    22. /* Writes a document start with the XML version number version. */
    23. xmlWriter->writeStartDocument();
    24.  
    25. /* Creer le noeud principal de toutes les spécialites*/
    26. xmlWriter->writeStartElement("Specialites");
    27.  
    28. /*
    29. --- Parcourcourir la requete et creer un noeud pour chaque spécialite
    30. --- Mettre les informations de la spécailité
    31. */
    32. while (speQuery.next())
    33. {
    34. // Creation du noeud de la spécialité
    35. xmlWriter->writeStartElement("Specialite");
    36.  
    37. /* ajouter attribut ID SPE*/
    38. xmlWriter->writeTextElement("Id", speQuery.value(0).toString());
    39.  
    40. /* ajouter attribut Nom spe*/
    41. xmlWriter->writeTextElement("Nom", speQuery.value(1).toString());
    42.  
    43. /* ajouter attibut Nom Long*/
    44. xmlWriter->writeTextElement("NomLong", speQuery.value(2).toString());
    45. }
    To copy to clipboard, switch view to plain text mode 
    The problem is that all data is displayed in one line in the file.
    Does anyone have an idea about this problem and can help me to resolve it.
    Many thanks in adavance.
    Best regards.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: XML Data displayed in one file

    Did You read QXmlStreamWriter doc ? I think : NO. Look at QXmlStreamWriter::autoFormatting

  3. The following user says thank you to Lesiok for this useful post:

    mourad (5th July 2012)

  4. #3
    Join Date
    Mar 2008
    Posts
    55
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    2

    Default Re: XML Data displayed in one file

    Thanks a lot for usefull response. It works fine.
    In fact, in the QXmlStreamWriter doc, it is indicated that the setAutoFormatting function was introduced in Qt 4.4 and I'm using 4.3 sothat i did'nt test it
    Thank for your help

Similar Threads

  1. Replies: 3
    Last Post: 8th June 2011, 07:36
  2. Reading XML file into a data file correctly?
    By falconium in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2011, 19:55
  3. Reading data from xls file
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2010, 10:33
  4. reading data from file
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2010, 11:31
  5. Data displayed via color map
    By bitChanger in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2006, 20:27

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
  •  
Qt is a trademark of The Qt Company.