-
Notifications
You must be signed in to change notification settings - Fork 0
Template XML basics
XML - eXtensible Markup Language - is a text file format with strict formatting rules. XML has quite a lot of capabilities, but for the sake of writing OTLoV templates only very basic XML understanding is required.
Normally, XMLs are stored in files with extension of .xml
(OTLoV looks only for .xml
files) and a structure of something like (example is taken from Microsoft article):
<?xml version="1.0" encoding="utf-8"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
...
</catalog>
NOTE:
...
denotes omitted text.
All XML files should start with a header:
<?xml version="1.0" encoding="utf-8"?>
This line tells that the file is XML, that it uses XML standard version 1.0 and that file encoding is utf-8
(encoding could be omitted, but it's recommended to always state it explicitly).
After the header a root XML element start. XML can have only ONE root element. You can't have more than 1. In sample above the root element is:
<catalog>
...
</catalog>
Root element name could be different - it depends on what your application is expecting. For OTLoV that would be:
<Template>
...
</Template>
XML file is based on XML elements and their attributes.
Attribute is a property of the element, a simple one, like id="bk101"
in the first book
element. Attribute value is ALWAYS a text. But the application (or schema, which we are not covering there) could specify that attribute text value must be convertible to specific type, like, an integer number. Then the value of the attribute is still written as text, say id="123"
, but the app will get it converted to actual number 123
, and if the value is not convertible - there could be an error.
For elements XML strictly requires that each element has a start and an end. This is especially important as XML allows children elements (tree) of any depth.
The start of element is always the same, but the end could differ a bit. XML has 2 notations for elements - full and short. Taking sample above the first book element is in full notation:
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
There a <book
is the start of an element and a </book>
is the end of the element. The element name is the book
, it must be the same in the start and in the end.
What if we don't need extra information and only need the book id? Then we could use short element notation:
<book id="bk101"/>
Here, a <book
is still the start of the element, but the end is denoted with />
instead.
Short element notation does NOT allow children elements. If you need children elements - you must use full notation.
XML standard reserves some characters for the XML formatting usage only. Also, XML doesn't support standard substitutions, like \n
for new line, like \t
for tab. Those characters must be substituted in special form. I've aggregated the most commonly used ones:
Character | In XML by name | In XML by dec code | In XML by hex code |
---|---|---|---|
< less then |
< |
< |
< |
> greater then |
> |
> |
> |
& ampersand |
& |
& |
& |
" double-quote |
" |
" |
" |
' apostrophe |
' |
' |
' |
\t tab |
	 |
	 |
|
\n new line |
|

 |