Modding:XML File Format Primer

From Lilith's Throne
Revision as of 05:34, 21 February 2024 by Sightglass (Sọ̀rọ̀ | contribs) (Page created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Lilith's Throne modding system loads in content as Extensible Markup Language (XML) text files. It's just text formatted to fit a certain structure, and they can be opened and edited by any text editor, though some will have tools like syntax highlighting and XML-checking tools to help catch mistakes.

Here's a dummy example, to show how things are structured:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<tag>

   <element>text content</element>

   <emptyTag/>

   <cdataElement><![CDATA[CData Stuff]]></cdataElement>

<elementWithAttribute attribute="attribute value" secondAttribute="second value">this is also content</elementWithAttribute>

<emptyTagWithAttribue attribute="this is also an attribute value"/>

   <outerElement>

       <nestedElement attribute="yet another attribute">this is content too</nestedElement>

<nestedElement attribute="yet another attribute">contented for a second</nestedElement>

   </outerElement>

</tag>

An XML file is arranged as elements, each having an opening tag <tag> and a closing tag </tag>.

The name of an element (which goes in the tag) follows a few simple rules:

  1. Must start with a letter or underscore ( _ )
  2. Cannot start with xml
  3. Are case sensitive!
  4. Cannot contain spaces!
  5. Can also have digits, hyphens, and periods, in addition to letters and underscores, but can't start with those (rule 1)

(Note: Most tag names used for LT are only letters with occasional numbers, and are usually in camelCase)

The stuff between the tags of an element, there may be content: <element>text content</element>. An element without content is usually entered as a self-closing tag ending in a slash: <emptyTag/>, or otherwise entered as tags with nothing between them: <tag></tag>. An element's content may be text or another element, which is called a child element: <element><childElement/></element>. Child elements can open with the same tag as others nested in the same parent.

Content for a tag in the form of <![CDATA[CData Stuff]]> is "character data", used to encapsulate text that may otherwise be interfere with the syntax of an XML document. For LT, it usually marks something that is sent to through a parser to perform scripting commands and/or displayed on screen as text.

Tags can also have attributes, which are key-value pairs included in the opening tag and formatted like: <tag key1="value1" key2="value2"></tag>. Each attribute in a tag must be unique.