More Tips on XHTML

by Jin, 03-26-09 // 0 comments

Recently I was involved in creating a web site that has a Spanish version and some web application sections, using XHTML Transitional doctype. I’d like to share couple tips.

You can also check out my previous article on XHTML validation.

Foreign Character Encoding

Consider the following header declaration for a standard English site:

<!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" lang="en">
<head>
<title>An English Site</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Description" content="I am an English site." />
</head>
<body>
I am an English site. Hello.
</body>
</html>

For Spanish site, use the following declaration:

<!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" lang="es">
<head>
<title>un sitio web en español</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="Soy un sitio web en español." />
</head>
<body>
Soy un sitio web en español
</body>
</html>

For Spanish:

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

You can find the complete list of foreign language code here.

For character encoding, utf-8 supports wider range.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Dynamic URL Encoding

In XHTML, single “&” is not allowed. The following anchor link will not validate.

<a href="script.php?areacode=555&sortBy=asc">Find Stores</a>

The “&” in the URL needs to be escacped as “&amp;”

<a href="script.php?areacode=555&amp;sortBy=asc">Find Stores</a>

This is easy to do, if the links are hard coded. However, there are times when the links are dynamically generated from the back-end, especially within web applications. This is when we need to use the URL encoding functions that is provided by the server side. Here’s a list of URL encode functions provided by commonly used back-end languages:

0 comments

also feel free to contact me on twitter or via email
Can you believe that no one has commented. Why don't you be the first?