Jump to content
  • Advertisement
Sign in to follow this  
boolean010

How can XML be used in a game

This topic is 3740 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 have been trying to find some info on the web about xml. I wasn't able to find much. The most I have is that is used to store data. How can I use it in a game. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
It is used to store data in an human readable format. It is very organized and lends itself well to tree structures, which occur very often in the real world, and thus in games. I have used it for UI stuff ie


<?xml version="1.0"?>
<dialog name="create_player" width="400" height="300">
<combo_box name="race" x="10" y="10" label="Choose your race: ">
<item>Elf</item>
<item>Human</item>
</combo_box>
<button name="continue" x="10" y="80">Continue</button>
</dialog>



something like that, then you have basic loading code, makes adding UI easy. Ogre3D uses XML for model/animation files, I have used it for maps, I tend to use it for everything. I have even used it on web based things over SQL, looking back, probably not a good choice.

Share this post


Link to post
Share on other sites
XML is a markup language — essentially a structured way of storing your data, potentially along with information about that data. One of the strengths of XML is that it is human-readable, and can potentially be edited by hand using a plain text editor (such as notepad). It's also possible to validate your XML to ensure that the markup is written in a way that makes sense and follows your rules.

Potential uses in games could be storing level data, information about different types of characters/weapons/equipment/whatever or anywhere else you have information you may want to store in a structured format, particularly if it's important to you that the data is human readable (and/or editable) without a special editor.

Downsides include the fact that XML can take up more disk space than neccesary for some purposes, and that it can sometimes be more difficult to save/load than a custom format (although there are of course many libraries that will help save you some of the work with this.


Like everything, XML is a tool that can make things easier for you when used appropriately but which may not be the best option in all situations. A couple of potential alternatives include writing your own custom data formats, Google's Protocol Buffers, or other existing formats.

Share this post


Link to post
Share on other sites
Nick Gravelyn has given some excellent tile engine tutorials, which includes a great use of XML (in that context, in C Sharp with XNA). May be of interest (its down at tutorial 12 or so).

The rest are also good if yoú´re learning the ropes!

clicky

Share this post


Link to post
Share on other sites
In lots of games XML is used on all variables that the developer wants to give easy access towards mod communities as well.

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!