Home > Articles > Web Services > XML

Day Four: Reformulating HTML into an XML Application

  • Print
  • + Share This
XHTML embraces the rules inherent to XML but allows you to use the rules of HTML. XHTML expert Molly Holzschlag discusses how to reformulate HTML into an XML application.

XHTML embraces the rules inherent to XML but allows you to use the rules of HTML. XHTML expert Molly Holzschlag discusses how to reformulate HTML into an XML application.

XHTML 1.0 reformulates HTML as an XML application. What this means is that it embraces rules inherent to XML but allows you to use the basic markup with which you are familiar: HTML. Of course, there are some changes that you'll have to adapt to, but in XHTML 1.0, these changes are relatively pain-free.

In terms of document-level regulations, the following three things must be in place for a document to be even considered as XHTML 1.0:

  • Documents must contain a DOCTYPE declaring the document as being an XHTML 1.0 document.
  • Documents must validate against one of the three available Document Type Definitions (DTDs) for XHTML 1.0.
  • Documents must contain an html root and an attribute that designates the XHTML namespace.

Now, those of you who have written valid HTML 4.0 documents know two of these rules: that the DOCTYPE declaration must be in place, and that the document must validate against a DTD. But for those who aren't familiar with such documents, these things might be confusing. Let me explain each one in turn.

A DOCTYPE declaration declares the document type. It does so by saying what type of document it is (HTML, XHTML, or whatever else you might be writing the document in). A DOCTYPE declaration appears at the very top of a document and also includes information about the type of DTD to which the document conforms.

In simple terms, a DTD is a list of all the elements, attributes, and values allowed in that particular language. A DOCTYPE declaration for an XHTML 1.0 document that will validate (that is, prove itself to conform to the rules set forth for a document of this type) against the transitional XHTML 1.0 DTD will read as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Even if you're familiar with DOCTYPE declarations from HTML 4.0, if you haven't yet studied XML, you'll be unfamiliar with namespaces. In XML, a namespace is another way of defining the type of document in question. In XHTML 1.0, the namespace must be included as an attribute and attribute value in the html root (the opening HTML tag), as follows:

<html xmlns="">http://www.w3.org/1999/xhtml">

The attribute xmlns stands for "XML namespace," and the value is the location of the document that describes the language in question (in this case, XHTML).

Because HTML is our vocabulary, when we look at a bare-bones XHTML document, we'll see familiar document formatting tags, including html, head, title, and body. Here's a sample transitional XHTML 1.0 document template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="">http://www.w3.org/1999/xhtml">
<head>
<title>Transitional XHTML 1.0 Document Template</title>
</head>

<body>

</body>
</html>

Looking at this code sample, you can easily begin to see how the familiar HTML vocabulary is set into a document that conforms to XML rules.

NOTE

You'll also see an XML declaration in XHTML 1.0 documents. This declaration states that the document is in fact an XML application. The XML declaration appears above the DOCTYPE declaration and is as follows:

<?xml version="1.0"?>

However, this declaration causes some browsers to render the document in plain text (in other words, it displays the markup and not the content), or it can cause the document not to render at all. Because the XHTML 1.0 standard states that the XML declaration is recommended but not required, many XHTML 1.0 authors leave it off at this time.

About the Author

An author, instructor, and designer, Molly E. Holzschlag brings her irrepressible enthusiasm to books, classrooms, and Web sites. Honored as one of the Top 25 Most Influential Women on the Web, Molly has worked in the online world for an almost unprecedented decade. She has written and contributed to more than 10 books about the Internet and, in particular, the Web.

Molly holds a B.A. in communications and writing and an M.A. in media studies from the New School for Social Research. You can visit her Web site at http://www.molly.com/.

Molly's most recent publications are Special Edition Using XHTML(Que, November 2000), Sams Teach Yourself Adobe LiveMotion in 24 Hours (Sams, June 2000), and Special Edition Using HTML 4.0, Sixth Edition (Que, December 1999).

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.