Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
The focus of this article is to explain why XHML is important and the
basics of an XHTML construct. It then details how the DTD that
one defines in an XHTML document relates to the XHTML Elements.
In the last article we discussed the
basics of XHTML. We talked about what it is, how it originated,
and how it is different from HTML. It is now time to put all
this good basic information to work.
In the next series of articles we are going to learn how to do
basic tables, frames, links and forms in XHTML structurally. We
will then follow that up with an article defining the differences
between document structure and document style, and then, as luck
would have it, we'll go back and visit these articles and apply
structure to them using style sheets. Fun, huh? So, are
you ready? Let's role up our sleeves and get to work.
The first thing we need to define is our basic XHTML document
format, the framework of which we will begin all our XHTML
pages. I have taken mine from the W3C website www.w3.org. My template is shown
below.
<?xml version="1.0" encoding="UTF-8"?>
<!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 xml:lang="en" lang="en"
<head>
document meta-information is put here
</head>
<body>
document content goes here
</body>
</html>
I might also mention here that the examples in these articles will
be using XHTML 1.0. Another noteworthy comment: XHTML
Basic just became a W3C recommendation so if you feel like doing some
reading you might want to pop over to the W3C website and check out
the differences between XHTML 1.0, XHTML basic, and XHTML 1.1.
OK, before we get started and delve into the good stuff we need to
have a quick discussion about DTD's. In each of the following
articles we will be discussing specific DTD's as they apply to each
topic (Tables, for example) so it is important to have a basic
understanding of them.
In the above XHTML framework you will notice that our document is
referencing a DTD (Document Type Definition):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
This means that our XHTML code needs to adhere strictly to the
format that is defined in this DTD. As you read through the
rest of our series, you will be wondering why the explanation of how
to create tables, forms etc are just such basic HTML
information. XHTML is HTML
with an XML flavor. But you can no longer have bad HTML
in your XHTML code. The structure of your XHTML document is
strictly defined in this DTD.
There are 3 DTD's that you can reference for XHTML:
Transitional: The DTD that is used when your web page
needs to be accessed by all older browsers which do not understand
stylesheets. You can still use the benefits of stylesheets in
your XHTML, but you can also make small adjustments to benefit
those browsers
Strict: This abides by the strictest XHTML specification
where you define your layout in your CSS. Therefore there are
no layout attributes in the document.
XHTML Frameset: This allows one to use HTML Frames to
partition the browser window into two or more frames.
In all our articles we will be using the Strict DTD except
in the article in which we discuss frames. In that article we
will be using the Frameset DTD. That is because the
Strict DTD does not support frames.
A quick description of a DTD construct is that it consists of
defining how the XML document should be structured. The main
definition building blocks are:
Elements
Attributes
Entities
Entities are like constants in Visual Basic, where you can define
the data for an entity, which can be used in the definitions of the
elements or attributes. For example let's look at the
definition for a line break (br) in the xhtml1-strict DTD
file.
<!ELEMENT br EMPTY>
<!ATTLIST br
%coreattrs;
>
<!ELEMENT br EMPTY>: The <br> element can only
contain an empty element therefore it can only have attributes but no
child elements.
<!ATTLIST br %coreattrs;> : This defines the
attributes associated with the <br> element. They are
using the %coreattrs entity, which if you look at defines that the
only attributes allowed for this element are id, class, style and
title. Which you may notice is the core attributes for a given
(X)HTML element. If you add any other attributes to this
element, you are creating invalid XHTML code.
For this article we are not explaining all the semantics of a
DTD. Our objective here is to allow you to see how the DTD fits
in with XHTML.
Just to give you a bit more information, the basis for every XHTML
document needs to be what was defined in our XHTML Template because
it is defined in the DTD as:
<!ELEMENT html (head, body)>
<!ATTLIST html
%i18n;
xmlns %URI; #FIXED 'http://www.w3.org/1999/xhtml'
>
The html element has to have child elements, head
and body. The html element must then have an
xmlns attribute which as defined in the URI entity which a fixed
value of 'http://www.w3.org/1999/xhtml'. (Plus other attributes
that is defined in the i18n entity, which we are not going
into look into now). But I think that you are beginning
to see the trend.
Because of this defined structure,
XHTML:
will be more
extensible than static HTML 4
it is leaner,
there it can be used for non-PC platforms like Palm-type computers,
telephones, televisions, etc.
you'll be able
to access the content of the document by using the DOM (Document
Object Model).
Well, it's now time to get to the good stuff. In the next
section we will be learning about XHTML tables.