XML Resource Files

Started by
2 comments, last by mcguile25 18 years, 4 months ago
Howdy all, Merry Christmas! I had a question regarding using XML files for my resources in my game. Let's take a simplistic case where I have an XML file that holds a list of all the text strings in the game. I decided on using TinyXML just because that's one that seems to be popular around here. The first thing you do with Tiny is call "LoadFile", and them from then on, you can call tiny's various functions to get elements and values and whatnot. My question is, at the application initialization, would I recursively grab all elements and their values and store this data in some sort of data structure OR would I do this: whenever a resource is needed, recursively find that element and its value with Tiny's parsing capabilities? Does this make sense? I guess I'm confused if I do the first method, how to store all that data or to go with the second method? Thanks!
Advertisement
I really depends on your application. If you can create a data structure that's easier or clearer to use than accessing TinyXML's DOM directly, then do that. Especially if you can store the data in a SC++L container.

If the data structure would just turn into a generic tree anyway, you might be better off just using TinyXML's API. Just make sure that you only load the document once, not everytime you access the file [smile].
In your example - which is basically an array of strings mapped to a name/index - it's probably easier to extract it all at load-time into a std::map object.

However it would be even better perhaps to use a StringTable resource in your .rc file - but I guess you just used this as an example?
Yeah, just an example. I'm also going to have music, sound effects, characters with various character info, fonts, etc.

This topic is closed to new replies.

Advertisement