Results 1 to 5 of 5

Thread: DomDocument to XML: producing empty files

  1. #1
    Join Date
    May 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default DomDocument to XML: producing empty files

    Hello,
    I am trying to take a QDomDocument and write to a .xml. I have got so far but now I can only produce empty documents.

    Qt Code:
    1. QDomDocument doc("MyML");
    2. QDomElement root = doc.createElement("MyML");
    3. doc.appendChild(root);
    4.  
    5. QDomElement tag = doc.createElement("greetings");
    6. root.appendChild(tag);
    7.  
    8. QDomText t = doc.createTextNode("Hello World");
    9. tag.appendChild(t);
    10.  
    11. QString xml = doc.toString();
    12. cout << qPrintable(xml) << endl;
    13.  
    14.  
    15. QFile file("something.xml");
    16. if (!file.open(QIODevice::WriteOnly))
    17. {
    18. QTextStream TextStream(&file);
    19. TextStream << xml;
    20. file.close();
    21. }
    22.  
    23. return 0;
    To copy to clipboard, switch view to plain text mode 

    and this produces

    Qt Code:
    1. <!DOCTYPE MyML>
    2. <MyML>
    3. <greetings>Hello World</greetings>
    4. </MyML>
    To copy to clipboard, switch view to plain text mode 
    any help would be much appreciated,
    Thanks,
    a.

  2. #2
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DomDocument to XML: producing empty files

    the test of your open is wrong

  3. #3
    Join Date
    May 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: DomDocument to XML: producing empty files

    the test of your open is wrong
    not particularly helpful... any more to add? something like doc.setContent? I haven't looked at it in a couple of days. I'll try again tomorrow I think.

  4. #4
    Join Date
    May 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Wink Re: DomDocument to XML: producing empty files

    ----------FIXED-------------

    Fixed the problem, really silly mistake.

    Qt Code:
    1. QFile file("something.xml");
    2. if (file.open(QIODevice::WriteOnly))
    3. {
    4. QTextStream TextStream(&file);
    5. TextStream << xml;
    6. file.close();
    7. }
    8.  
    9. return 0;
    To copy to clipboard, switch view to plain text mode 

    Changed the condition in the if loop. Removed not operator, duh! Works perfectly now.

  5. #5
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DomDocument to XML: producing empty files

    that's what i was saying

Similar Threads

  1. Replies: 1
    Last Post: 14th November 2011, 09:58
  2. is QString empty?
    By timmu in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2010, 22:17
  3. Producing PDF
    By giusepped in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2008, 08:41
  4. Producing Keypressed Event
    By anafor2004 in forum Newbie
    Replies: 11
    Last Post: 30th April 2008, 10:19
  5. remove directory empty or not empty
    By raphaelf in forum Newbie
    Replies: 12
    Last Post: 27th October 2006, 07:30

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.