Results 1 to 4 of 4

Thread: Creating new XML file

  1. #1
    Join Date
    May 2009
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Red face Creating new XML file

    Hey guys, I have the following code:

    Qt Code:
    1. void xmlBaseTest::myBlankFile()
    2. {
    3. QFile data("booklist.xml");
    4. QDomElement root = doc->createElement("booklist");
    5. doc->appendChild(root);
    6.  
    7. if (data.open(QFile::WriteOnly | QFile::Truncate)) {
    8. QTextStream out(&data);
    9. doc->save(out,4);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    It creates the file:
    Qt Code:
    1. <!DOCTYPE serverlist>
    2. <booklist/>
    To copy to clipboard, switch view to plain text mode 

    The line <booklist/> is causing problems, when trying to read it later using .setContent. I was wondering if there was any way to get it to print out <booklist></booklist> instead?

    Thanks much

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating new XML file

    It can't be causing problems, it's perfectly valid. What exactly are the "problems"?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating new XML file

    I have an other question about "valid XML":
    is it possible to create a header line
    <?xml version=\"1.0\" encoding=\"iso8859-1\" ?>"
    by some calls of whatever or do I have to set them with

    Qt Code:
    1. DomDocumentType doctype = impl.createDocumentType("name", QString::null, QString::null);
    2. QDomDocument doc = impl.createDocument("uri", "name", doctype);
    3. doc.setContent(QString("<?xml version=\"1.0\" encoding=\"iso8859-1\" ?>"));
    To copy to clipboard, switch view to plain text mode 

    Sorry, this piece of code is from Qt3. Until now I did not face the differences of XML code in Qt4.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Creating new XML file

    Quote Originally Posted by auba View Post
    <?xml version=\"1.0\" encoding=\"iso8859-1\" ?>"
    Qt Code:
    1. QDomDocument doc("RootElement");
    2. QDomProcessingInstruction process = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"iso8859-1\"");
    3. doc.appendChild(process);
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Lykurg for this useful post:

    auba (16th May 2009)

Similar Threads

  1. Creating a form.ui by a Designer + implementing to .cpp file
    By thewooferbbk in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2009, 08:25
  2. Creating a dll file under windows
    By schall_l in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2008, 11:55
  3. Issue creating lib file
    By TheGrimace in forum Newbie
    Replies: 2
    Last Post: 7th June 2007, 16:30
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Replies: 7
    Last Post: 31st May 2006, 09:37

Tags for this Thread

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.