Results 1 to 8 of 8

Thread: Save/Load a game level using XML.

  1. #1
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile Save/Load a game level using XML.

    Hi friends!

    My level editor must save/load its levels, and I wonder what is the best choice,
    QXmlStreamWriter/QXmlStreamReader OR QDomDocument/QDomElement/doc.toString()?

    I mean, after reading docs, I guess both of them could work perfeclty, but I would like to hear your suggestions. What is easier or most suitable?

    Thanks in advance.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save/Load a game level using XML.

    QDom will take a little more memory because it holds the xml structure in memory. Stream readers values can be assigned to your internal tree and thus are accesed fast.
    but if you want to add new content to the xml.. then go for QDom

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

    ricardo (12th July 2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save/Load a game level using XML.

    Quote Originally Posted by MrDeath View Post
    QDom will take a little more memory because it holds the xml structure in memory. Stream readers values can be assigned to your internal tree and thus are accesed fast.
    but if you want to add new content to the xml.. then go for QDom
    Thanks for reply.

    Memory is not a problem (is a level editor, for private use), but what do you mean exaclty with "if you want to add new content to the xml.. then go for QDom"?

    Does that mean it is hard to add new content using QXmlStreamWriter?

    Thanks.

  5. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Save/Load a game level using XML.

    You can use DOM as you database. In this case QDom is the best choiche.

    If you use different structure to hold your data and then re-write each time your XML, QXmlStreamWriter if better.
    A camel can go 14 days without drink,
    I can't!!!

  6. The following user says thank you to mcosta for this useful post:

    ricardo (12th July 2009)

  7. #5
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save/Load a game level using XML.

    Quote Originally Posted by mcosta View Post
    You can use DOM as you database. In this case QDom is the best choiche.

    If you use different structure to hold your data and then re-write each time your XML, QXmlStreamWriter if better.
    Excuse me, I don't understand you very well.

    Probably I will modify my level structure frecuently. Is in this case QXmlStreamWriter/Reader a better choice?

    BTW, thanks.
    Last edited by ricardo; 12th July 2009 at 13:11.

  8. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save/Load a game level using XML.

    if you modify your structure of xml then qdom is better.
    do not confuse it with adding data to xml..
    for example suppose your xml looks like this
    Qt Code:
    1. <nodes>
    2. <child></child>
    3. <child></child>
    4. </nodes>
    To copy to clipboard, switch view to plain text mode 

    you can add or delete as many child as needed, this does not changes the xml structure, so you can use
    both qdom and stream

    but if you modify your xml structure like
    Qt Code:
    1. <nodes>
    2. <child></child>
    3. <newChild></newChild>
    4. </nodes>
    To copy to clipboard, switch view to plain text mode 
    here we have modifed the structure, this is where QDom is easy. (just make the changes and say doc->save())

  9. The following user says thank you to nish for this useful post:

    ricardo (13th July 2009)

  10. #7
    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: Save/Load a game level using XML.

    There are two scenarios

    The one MrDeath describes, you load the xml in the dom and do the chances there. Then use of course QDomDocument.

    Second: You read the xml file and store all information in a custom class with QStringList, QHash etc. Your editing and chancing is done in that containers and then you want to save them, then use QXmlStreamWriter/QXmlStreamReader

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

    ricardo (13th July 2009)

  12. #8
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save/Load a game level using XML.

    OK, thanks, I will use QDom.

Similar Threads

  1. Replies: 0
    Last Post: 22nd February 2009, 13:15
  2. Replies: 1
    Last Post: 21st November 2008, 16:06
  3. QT debug confusion
    By swistak in forum Installation and Deployment
    Replies: 2
    Last Post: 24th September 2008, 19:25
  4. Algorithms problem of brackets including.
    By luffy27 in forum General Programming
    Replies: 2
    Last Post: 12th April 2007, 01:10

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.