XML
Structure
An XML document consists of the prolog (optional, but considered good
form), the document body and the epilog. The prolog provides information
abou the document itself and includes the XML declaration, the DTD and
miscellaneous statements or comments. The XML declaration is always
the first line of code:
<?xml version="version number" encoding="encoding
type" standalone="yes/no" ?>
Version numer by default is "1.0" (the only version currently).
The encoding type allows you to use XML with a variety of languages.
The default coding scheme is English, or "UTF-8." The standalone
attribute tells the parser whether or not the document has any links
to external files. By default, if you omit the standalone attribute,
the parser assumes yes.
Elements and Attributes
Elements in XML are similar to those in HTML and may be open or closed.
There are several rules you must be familiar with regarding XML elements:
- Names are case sensitive
- Names must begin with a letter or underscore
- Names cannot contain blank spaces
- Names cannot begin with xml
- The name of the closing tag must exactly match the name of the opening
tag
- Elements can be nested as child elements
- You must close a child element before closing the parent element
(much more strict than HTML.)
The nesting concept applied to the whole document. All elements are
nested within a single document or root element.
An open or empty element is one that contains no content. The syntax
of an empty element tag is:
<emptyelement/>
Attributes describe a characteristic of an element. The syntax for
adding an attribute is the same for HTML. Attributes are case sensitive,
must also begin with a letter or underscore, must not include spaces
and can only appear once in the same starting tag.
<element attribute="value">Content</element>
<track length="9:22">So What</track>
There is some debate about the use of attributes. Some say you should
never use attributes because they add to the complexity of the document
with the information better placed within an element. Most agree it
is best to use attributes only for information that is processed by
the parser but does not need to be viewed.