XML Quick Primer

From Academia: School Simulator
Jump to: navigation, search

XML is a text format for defining data. Text format here means that it is readable and writable by humans, but at the same time it has a structure that can be read by a computer program. Manipulating an XML file is not programming. It's just a means to define data. If you're familiar with HTML, they look somewhat the same. That's because HTML is a subset of XML. HTML is interpreted by web browsers. For Academia, the game uses XML to read various data. You will encounter this file format while making mods. This primer will help you understand XML.

Tags

Anything enclosed in <> is referred to as a tag. For example <Person> is a tag. There are two types of tags - starting tag and ending tag. <Person> is a starting tag, while </Person> is an ending tag. The only difference is ending tags start with "</". The text between <> is called a tag name.

Elements

Any set of starting tag and ending tag with the same tag name is considered as an element. For example, <Person></Person> is a Person element.

Elements can have child elements. For example, this is a Person element with 3 Child elements:

<Person>
  <Child></Child>
  <Child></Child>
  <Child></Child>
</Person>

Alternatively, elements with no children can be written like this <TagName/>. This saves us from writing the ending tag. For example, the previous XML can be written as

<Person>
  <Child/>
  <Child/>
  <Child/>
</Person>

Attributes

Elements can have attributes. They are in the form of attribute="value" inserted along starting tags. Elements can have any number of attributes. For example, the elements here now have name and gender:

<Person name="Mary Lufkin" gender="Female">
  <Child name="Mike Lufkin" gender="Male" />
  <Child name="Heather Lufkin" gender="Female" />
  <Child name="Gary Lufkin" gender="Male" />
</Person>

Comments

Text that is enclosed within <!-- and --> are comments. They are ignored when they are read by programs. However, they are important for humans to write reminders or to simply give further details about the XML.

<!-- This is a single line comment -->
<!--
This is a multi line comment.
Here's a second line to give a point.
Here's another one. :)
-->
<Person name="Mary Lufkin" gender="Female">
  <Child name="Mike Lufkin" gender="Male" />
  <Child name="Heather Lufkin" gender="Female" />
  <Child name="Gary Lufkin" gender="Male" />
</Person>

What to expect?

XML formats used in Academia are very simple. We try to simplify them as much as we can. Expect a flat hierarchy on the game's XML files like how the Person example here is presented. For modding, you will be required to add elements and edit attribute values. As an example, this is a TileSpriteMapping.xml of a sample mod:

<TileSpriteMapping>
  
  <!-- Character Textures -->
  <Entry id="Characters" streamingPath="Images/Characters/CharacterTexturePrison.png" pack="false" />

</TileSpriteMapping>

What editor to use?

Being a text format, Notepad is enough, but we highly recommend Notepad++ or other editors that specifically supports XML and has some sort of coloring and validation (tells you when your XML is wrong). The previous XML looks like this in Notepad++ which looks better.
NotepadPPSample.png