Parsing an XML file periodically

Hi everyone,

I’m currently working on a tablet game that needs to parse an XML file, which actually contains a whole database structure (several DB tables). The file is previously loaded to the tablet.

I need to select and return some elements from the XML file periodically – not at regular intervals, though. In fact, these elements are chosen according to a specific algorithm.

I’m programming in C#, and several ideas came to me, such as:

  • Parsing the XML file with XmlReader every time I need to return elements
  • Parsing the XML file at the beginning of the game only, saving its data to a hashtable, and working with the hashtable each time I’ll need to select elements

I could implement the former solution with Linq to XML too, but I’ve read that XmlReader was the fastest way to parse huge XML files.

The latter solution looks good to me, but I have no idea where to “store” the hashtable (in some cache memory, maybe?).

What would you advise me to do?

Thanks in advance!

XmlReader can impact performance (less so with 3.5 thanks to rendering now in a separate thread), but if the data does not change throughout the game, load it at the start and store it. If your game has more than one scene and you need to keep it around, google ‘singleton’ or just use this: http://unity3d.com/support/documentation/ScriptReference/Object.DontDestroyOnLoad.html Basically your first scene would load it into some script, and you use that function to say ‘don’t destroy this game object holding this script’ and it will persist across different scenes.

Could you not used Liquid XML Editor to parse your xml for you? it also as a built in xml database mapper and a large file editor.