Jump to content
  • Advertisement
Sign in to follow this  
gah_ribaldi

Using XML for UI data

This topic is 3541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm putting together a 2D game and thinking that it might be fun (or at least good practice/learning) to use XML to hold the data for the UI, e.g. position and texturing of components. Any thoughts / tips? I'm programming in C++ with openGL

Share this post


Link to post
Share on other sites
Advertisement
It's what we do on Championship Manager and it serves us pretty well considering it is such a UI heavy game. XML provides a natural hierarchy that matches a typical UI hierarchy so it's an automatic choice really.

Hope that helps,

Share this post


Link to post
Share on other sites
You could either write your own XML parser (which isn't too difficult) or a 3rd party wrapper.

I personally approached building an XML parser in the following way:

First I worked out how I would represent the XML tag tree internally. The most obvious route to my mind is using linked lists. Each tag is represented by an object that links to the parent tag in previous level of the tree and all the child tags below it in the tree. The object contains a list of all the different attributes that are described in the XML document.

When loading the XML file the parser switches between states depending on where it is based on the XML syntax. States include being in a comment or being in a tag or in white space. The state defines how the current character that is being read is dealt with.

Whenever a tag is read in an object is created. There is a stack of tags which keeps track of which tag is the parent tag to all its child tags; so if it has seperate closing tags (in that it can encapsulate child tags) then when the object is create it links to the tag on the top of the stack and then pushes itself onto the stack so any child tags will link to it as a parent and they can be added to the vector of children within the parent tag. Once the parent tag closes it is popped off the top of the stack and so the previous parent is now at the top of the stack.

In all this builds up an XML tree. And as long as you keep track of which object is the root of the tree then you can quickly traverse through it using recursion.

I love XML and am using it to describe pretty much everything in my projects now. Its definitely a useful system to write!

Hope that helps

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!