Saving parsed XML data to memory

Hello everyone,

My Bitmap fonts and HUD make use of XML files to help define them, both files are rather small ~30 KB about. The Font XML is parsed once at engine startup and the HUD file once when world is created.

I use DOM to parse them (DocumentBuilderFactory etc.), what system should I use to save the parsed data to for later use during the main game loop(tick), a Hash map, or what? Obviously I want it to be quick and not take to much memory.

If this approach is wrong please tell me, I will try any other methods you think would be better.

Thanks

What I did was create a simple asset library that stores things in a hashmap. At start up, whatever is being drawn reads in the asset library and sets up direct references to the



public HUD(AssetLibrary aLib) {
   this.mainFont = aLib.getFont("HUDFont");
}

...

public void draw(SpriteBatch batch) {
   ...
   this.mainFont.draw("HEALTH: "+player.health);
}

It’s fast, and your Asset Library is only needed when the main objects are created, not at every tick. There is a bit more memory being used because you are holding additional references to the various items in your asset library, but it shouldn’t matter (hasn’t been a problem for me).

Thanks, I am going to create a similar solution using a AssetManager.

Question though what do you use to parse XML with? or recommend.

I use the built in SAXParser and found it very easy to work with. Googling SAXParser tutorial should bring up lots of resources.