PDA

View Full Version : Save/Load a game level using XML.



ricardo
10th July 2009, 20:31
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.

nish
12th July 2009, 03:36
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

ricardo
12th July 2009, 10:39
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.

mcosta
12th July 2009, 11:03
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.

ricardo
12th July 2009, 13:02
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.

nish
13th July 2009, 02:45
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

<nodes>
<child></child>
<child></child>
</nodes>

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

<nodes>
<child></child>
<newChild></newChild>
</nodes>
here we have modifed the structure, this is where QDom is easy. (just make the changes and say doc->save())

Lykurg
13th July 2009, 08:27
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

ricardo
13th July 2009, 09:45
OK, thanks, I will use QDom.