XML Basic Format

Intro

XML is quite a simple language. Anybody can work it out, and in Civ IV, you can make quite powerful mod by just changing a few lines in the XML file.

Like pretty much any computer language, XML has a set syntax for entering data. If you don't follow this syntax, your file won't work, and your mod won't run. The format, thankfully, is very much like HTML, and VBCode, so is quite easy to pick up.

XML can be accessed using pretty much any text reading software - even notepad. There are several programs scattered around the net which can help. A lot of people use Altova XMLSpy 2008, which sets things up for you, and puts all the data in a more organised fashion.

There are many adequate freeware editors available, such as XML Notepad. These programs do syntax checking and prevent you from creating an invalid XML file. It's much easier to use one of these graphical editors to prevent wasting time with small syntax errors.

Now, onto some examples.

Basics

1-line tags

The basic format of XML is as follows:

<Tag>DATA</Tag>
Each piece of data must be surrounded by tags, or it won't work.

Most of the tags are defined inside the file you will be editing. For example, the settler unit has the tag:

<Class>UNITCLASS_SETTLER</Class>
If you wished to change the class of the unit, you would only have to change the data part, and not the tag.

There are one or two more things about tags I haven't gone into yet. Some of the tags in .xml files are used for storing single pieces of data, and some multiple pieces. The <Class> tag above is a good example of a single piece of data stored between tags. There is only one piece of data that can go there, and it can be changed.


Types of 1-line tags

There are severial types of one line tags:

Text tags

These are your basic text tag. They usualy refer to other parts of different files, and often have a set format. For example, a text tag for a unit requring iron working would read:
<PrereqTech>TECH_IRON_WORKING</PrereqTech>
Note that spaces in text tags should be replaced with underscores.

  • Due to the way that XML handles whitespace, it is good practice to always use underscores instead of spaces in data strings.
  • The exception to this general rule would be when your data string is specifically the in-game display name of an object or item.

Boolean tags

These tags must either have a value of 1 (on, active), or 0 (off, inactive). These tags look like this:
<bTag>1</bTag>
This tag would be active. It is importatnt to note in certain circumstances the tag may be counter intuative, for example:
<bDisable>1</bDisable>
will mean that the operation IS disabled, not the other way around (I have seen confusion on this matter).

Integer tags

These tags must have an integer (whole) number in them, they look like this:
<iTag>233</iTag>

Floating point tags

Much like integer tags, but these must have a decimal number in:
<fTag>2.33</Ftag>


Multiple line tags

Tags with multiple pieces of data have the following syntax: (taken, and slightly altered from the worker unit)

<Builds>
<Build>
<BuildType>BUILD_ROAD</BuildType>
<bBuild>1</bBuild>
</Build>
<Build>
<BuildType>BUILD_RAILROAD</BuildType>
<bBuild>1</bBuild>
</Build>
<Builds>

The main tag in this case is <Builds>, and inside this tag there are two <Build> tags, each containing a <BuildType>, and a <bBuild> tag. Note the subtle difference between <Builds and <Build>. I have been tripped up by this myself, so be careful! :)

The indentation used in this example is not necessary, however, when reading the .xml file, it makes the tags seem alot clearer. In actual fact, all .xml data could be put on one line - like this:
<Tag><Tag2>DATA</Tag2></Tag>
but it gets quite hard to read, so it is usual to spread it out a bit!

If you have a tag that is designed for many other tags to be used between it, yet you want to place nothing in there, you can use the syntax:
<tag/>


Comments

XML files can have comments, which are where you describe what the file is doing. Comments are ignored by the game engine. XML comments are contained in <!-- --> tags, like this:
<!-- This is a comment, and it can span multiple lines -->
NB. There are some xml files which don't like comments. CIV4TechInfos.xml is an example of this - the techtree will not work properly if comments are inserted.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License