Public Group

How can XML be used in a game

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

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 on other sites
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 on other sites
Thanks for taking the time to reply.

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 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 on other sites
Thanks, I'll take a look.

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.

• 11
• 19
• 12
• 34
• 9
• Forum Statistics

• Total Topics
631398
• Total Posts
2999838
×