Next / Previous / Contents / TCC Help System / NM Tech homepage

3. Rules for the XML notation

XHTML uses the rules for XML (eXtensible Markup Language) to structure your document. Here is a brief summary of XML; you must adhere to these rules to construct a valid XHTML document.

It is good practice (though not required) to start your document with a DOCTYPE declaration that specifies that it is written in XHTML. For the recommended format of this declaration, see Section 2, “A small, complete example page”.

Structure your document with tags. Each tag starts with a less-than symbol (<) and ends with a greater-than symbol (>).

Each tag defines the start or end of a region of the page. Such a region is called an element. Most elements consist of a start tag, followed by some content, followed by an end tag.

A start tag has this general format:

<type attrname="attrvalue" …>

where the type indicates the kind of tag. Following the type name there may be zero or more attributes that describe various properties. Each attribute consists of an attribute name, followed by an equal sign, and a value enclosed in quotes. You may use either double quotes (e.g., id="Neptune") or single quotes (e.g., class='disreputable') to enclose the attribute's value.

An end tag has this format:

</type>

Some whitespace (any mixture of spaces, tabs, and newlines) is required between the type and the first attribute, and also between attributes. Space is also allowed before the closing “>”.

XML also allows a different type of element called the empty element. Here is the general form of an empty element:

<type attrname="attrvalue" …/>

An empty element functions exactly the same as a start tag and an end tag with nothing between them. These two lines are functionally identical in XHTML:

<hr class='heavy'></hr>
<hr class='heavy'/>

Elements must be properly nested. That is, there must be an html element, called the root element, that encloses all other elements on the page. Also, an element must be completely inside, or completely inside, other elements. You can't have two elements that partially overlap; for example, the sequence “<h1>Analyzing <cite>Ulysses</h1></cite>” is not valid because the cite element is partially inside and partially outside the h1 element.

XML allows you to place comments in your document. Here is the general form of a comment:

<!--text-->

where text is any text. The text may not contain two consecutive hyphens (--).