- 55 -
Okay, you’ve waited patiently enough. Let’s get our hands dirty and start exploring the
nitty-gritty details. We begin by going over the XML document syntax.
XML Document Syntax
As
we mentioned earlier, an XML document is made of content (character data)
encapsulated in markup. There are seven types of markup that can be used in an XML
document:
•
Element start and end tags
•
Attributes
•
Comments
•
Entity
references
•
Processing instructions
•
Character data sections (CDATA)
•
Document type declarations
In the next few sections, we go over each type of markup with
examples of how to use
them.
Element Start and End Tags
Elements are the most basic building blocks of XML documents. They can be used to
both contain information and define structure. An element starts out
with a starting tag
and ends with a corresponding ending tag.
The start tag consists of a single word (no spaces allowed) surrounded by the < and >
characters. If you’re familiar with HTML,
is an example of a start tag. Similarly, an
end tag example is
. Table 3.1 shows some examples of element tags and their
usage.
Table 3.1 Element Start and End Tag Syntax
Tag
Description
An allowable starting tag for the first_tag element
The corresponding ending tag for the first_tag element
Incorrect usage—element names cannot include spaces
<1st_tag>
Incorrect usage—element names cannot begin with a number
- 56 -
first_tag>
Incorrect usage—spaces are not
allowed between the forward
slash and element name
Keep in mind that XML is case sensitive. Element names must therefore open and close
with identical cases. For example:
110 Main Street
is not acceptable whereas each of the following examples is acceptable:
110 Main Street
110 Main Street
110 Main Street
Also keep in mind that each of these is treated separately. From a parser’s
point of view,
each of these examples is a different type of element.