Now that you have had a quick taste of working with XML, here is an overview of the more common rules and constructs of the XML language.
These are the rules for a well-formed XML document:
The document must either use a DTD or contain an
XML declaration with the
standalone attribute set to
“no”. For example:
<?xml version="1.0" standalone="no"?>
All element attribute values must be in quotation marks.
An element must have both an opening and closing tag, unless it is an empty element.
If a tag is a standalone empty element, it must contain a closing slash (/) before the end of the tag.
All opening and closing element tags must nest correctly.
Isolated markup characters are not allowed in text:
& must use entity references instead. In addition, the
]]> must be expressed as
]]> when used as
regular text. (Entity references are discussed in further detail
Well-formed XML documents without a corresponding DTD must have all attributes of type CDATA by default.
The following XML instructions are legal.
An element is either bound by its starting and ending tags, or is an empty element. Elements can contain text, other elements, or a combination of both. For example:
<para>Elements can contain text, other elements, or a combination. For example, a chapter might contain a title and multiple paragraphs, and a paragraph might contain text and <emphasis>emphasis elements</emphasis>:</para>