XML is a particularly interesting format for me. For those of you who don't know what XML is, it's a text based markup language that can be extended to include the tags and attributes you require for describing your data. It has many components that make it both simple and complex. You can write up schema's, in XML, that describe how an XML document should be laid out, what elements go where, and what attributes those elements have. You also have the ability to essentially free form it, avoiding the need to use a schema, although at the cost of verifiability.
Now, before you go jumping all over XML to do everything, don't. XML has its uses, but it certainly isn't an all purpose solution to every problem. Using XML is just like using patterns: For some people, once they've got the hammer, they see everything as a nail. There are some things I would never use XML for, such as a model file. While models as XML sound like a great idea at first, in reality it just isn't needed. First of all, a binary format will be smaller than the XML equivalent. Secondly, a model file really isn't humanly readable. The values don't make a whole hell of a lot of sense, and so there is no reason to bother with the added size that XML gives, since you get nothing back.
Because XML is text, and hence can be read by a human, it gives us the ability to put into text format certain features of a game that are easier done in text than binary. Lets look at a simple example:
"1.0"
"1">
Orc
"6" count="2" />
"4" count="1" />
"1" />
"3" />
"3" maxAmount="10" />
"5" chance="0.001" />
This looks fairly simple, and it's easy to read too. We can tell that we have an Orc here, with between 2 and 12 hit points, and a base armor class between 1 and 4. We also see that it has a weapon, and some armor, and drops an amount of gold, along with some item. But what are these weapons, armor, and items? Well, lets take a look at the item.xml:
"1.0"
"1">
Short Sword
A small cheaply crafted iron sword.
"weapon" subtype="1hsword">
"4" count="2"/>
"3">
Leather Armor
A crudely crafted armor made from the skin of animals.
"armor" subtype="light">
"4" count="1" />
"5">
Ruby
A brilliant red gemstone.
"treasure" subtype="gemstone">
"6" count="3" />
So, now we can see that our Orc is wearing Leather Armor, holding a Short Sword, and has a 1 in 1000 chance of dropping a ruby, along with some gold. Looks fairly descriptive, easy to read and change, wouldn't you say?
Next time we'll look at using XSLT to add more information to this document.
I really wish you would have mentioned this earlier. *Stops manual parsing techniques* [grin]