1 XML IN FIFTEEN MINUTES OR LESS
3 Written by David Megginson, david@megginson.com
6 This document is in the Public Domain and comes with NO WARRANTY!
12 FlightGear uses XML for much of its configuration. This document
13 provides a minimal introduction to XML syntax, concentrating only on
14 the parts necessary for writing and understanding FlightGear
15 configuration files. For a full description, read the XML
20 This document describes general XML syntax. Most of the XML
21 configuration files in FlightGear use a special format called
22 "Property Lists" -- a separate document will describe the specific
23 features of the property-list format.
26 2. Elements and Attributes
27 --------------------------
29 An XML document is a tree structure with a single root, much like a
30 file system or a recursive, nested list structure (for LISP fans).
31 Every node in the tree is called an _element_: the start and end of
32 every element is marked by a _tag_: the _start tag_ appears at the
33 beginning of the element, and the _end tag_ appears at the end.
35 Here is an example of a start tag:
39 Here is an example of an end tag:
43 Here is an example of an element:
45 <foo>Hello, world!</foo>
47 The element in this example contains only data element, so it is a
48 leaf node in the tree. Elements may also contain other elements, as
52 <foo>Hello, world!</foo>
53 <foo>Goodbye, world!</foo>
56 This time, the 'bar' element is a branch that contains other, nested
57 elements, while the 'foo' elements are leaf elements that contain only
58 data. Here's the tree in ASCII art (make sure you're not using a
61 bar +-- foo -- "Hello, world!"
63 +-- foo -- "Goodbye, world!"
65 There is always one single element at the top level: it is called the
66 _root element_. Elements may never overlap, so something like this is
67 always wrong (try to draw it as a tree diagram, and you'll understand
72 Every element may have variables, called _attributes_, attached to
73 it. The attribute consists of a simple name=value pair in the start
76 <foo type="greeting">Hello, world!</foo>
78 Attribute values must be quoted with '"' or "'" (unlike in HTML), and
79 no two attributes may have the same name.
81 There are rules governing what can be used as an element or attribute
82 name. The first character of a name must be an alphabetic character
83 or '_'; subsequent characters may be '_', '-', '.', an alphabetic
84 character, or a numeric character. Note especially that names may not
91 Some characters in XML documents have special meanings, and must
92 always be escaped when used literally:
97 Other characters have special meanings only in certain contexts, but
98 it still doesn't hurt to escape them:
104 Here is how you would escape "x < 3 && y > 6" in XML data:
106 x < 3 && y > 6
108 Most control characters are forbidden in XML documents: only tab,
109 newline, and carriage return are allowed (that means no ^L, for
110 example). Any other character can be included in an XML document as a
111 character reference, by using its Unicode value; for example, the
112 following represents the French word "cafe" with an accent on the
117 By default, 8-bit XML documents use UTF-8, **NOT** ISO 8859-1 (Latin
118 1), so it's safest always to use character references for characters
119 above position 127 (i.e. for non-ASCII).
121 Whitespace always counts in XML documents, though some specific
122 applications (like property lists) have rules for ignoring it in some
129 You can add a comment anywhere in an XML document except inside a tag
130 or declaration using the following syntax:
134 The comment text must not contain "--", so be careful about using
141 Every XML document may begin with an XML declaration, starting with
142 "<?xml" and ending with "?>". Here is an example:
144 <?xml version="1.0" encoding="UTF-8"?>
146 The XML declaration must always give the XML version, and it may also
147 specify the encoding (and other information, not discussed here).
148 UTF-8 is the default encoding for 8-bit documents; you could also try
150 <?xml version="1.0" encoding="ISO-8859-1"?>
152 to get ISO Latin 1, but some XML parsers might not support that
153 (FlightGear's does, for what it's worth).
159 There are other kinds of things allowed in XML documents. You don't
160 need to use them for FlightGear, but in case anyone leaves one lying
161 around, it would be useful to be able to recognize it.
163 XML documents may contain different kinds of declarations starting
164 with "<!" and ending with ">":
166 <!DOCTYPE html SYSTEM "html.dtd">
168 <!ELEMENT foo (#PCDATA)>
170 <!ENTITY myname "John Smith">
172 and so on. They may also contain processing instructions, which look
173 a bit like the XML declaration:
175 <?foo processing instruction?>
177 Finally, they may contain references to _entities_, like the ones used
178 for escaping special characters, but with different names (we're
179 trying to avoid these in FlightGear):