XML Reference

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.

Well-Formed XML

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: < or & must use entity references instead. In addition, the sequence ]]> must be expressed as ]]&gt; when used as regular text. (Entity references are discussed in further detail later.)

  • Well-formed XML documents without a corresponding DTD must have all attributes of type CDATA by default.

XML Instructions

The following XML instructions are legal.

Element and Attribute Rules

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>

An ...

Get XML Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.