Waffle

« Nice pigs sir! | Home | SXSW road trip »

The XML prolog — what’s in a name?

There are some reasonably authoritative voices in the web standards
community which at the time of writing are using the technical term XML prolog when they actually mean
XML declaration.

The XML 1.0 specification provides a clear definition of the prolog:

document
document ::= prolog element Misc*
prolog
prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?

Put simply this means that in XML the prolog refers to the stuff before
the root element (In the case of XHTML the HTML element). So in the
following XHTML 1.0 example the prolog contains an XML declaration, a
comment, a
stylesheet declaration, a document type declaration and some white
space
.

<?xml version="1.0" ?>
<!-- Poor old IE6 goes into quirks mode -->
<?xml-stylesheet href="#blueskin" type="text/css" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
[...]
</html>

In this prolog everything except the document type declaration is optional.

In the article Browser Problems with the XML Prolog, The WaSP mistakenly refers to the XML declaration as the prolog:

Using the XML prolog in XHTML documents is a practice that is
recommended but not required by the W3C. So, it’s up to you whether to
use it or to leave it out. Here’s an example of what the prolog looks
like: <?xml version="1.0" encoding="UTF-8" ?>

Actually the W3C by way of the XHTML 1.0 spec infers that an XML prolog is required. What is “recommended but not required” is an XML declaration, and the authors’ given example of
“the prolog” could only possibly be considered the prolog in
extraordinary circumstances[1]. What this example “looks like” is an XML declaration.

The XHTML 1.0 recommendation:

There must be a DOCTYPE declaration in the document prior to the root element.
[…]
An XML declaration is not required in all XML documents; however XHTML document authors are strongly encouraged to use XML declarations in all their documents.
http://www.w3.org/TR/xhtml1/#strict

Surprisingly even Tantek Çelik mixes up the two terms.
In his instructional Minimal XHTML 1.0 Document Tests the term XML prolog is used when XML declaration is meant.
In this document each of these examples has an XML prolog, the examples which Tantek describes as “without ?xml prolog:” are actually without XML declaration.

A conforming XHTML document must contain a prolog — at least a Document Type Declaration as prescribed in the recommendation.

[1] This is the only usage of an XML declaration where it might also be considered the prolog.

<?xml version="1.0" ?><html>
[...]
</html>

As you can see this is not XHTML.

* Jeff Lowder has created a graphic which illustrates the example prolog I gave here. Thanks Jeff.

Browse Happy logo