HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [23]
If you already know some HTML, you’re gonna hate the validator for a while because it rejects coding habits that you might think are perfectly fine. Unlearning a habit is a lot harder than learning a new practice, so I feel your pain. It’s still worth it.
After you discipline yourself to validate your pages, you’ll find you’ve picked up good habits, and validation becomes a lot less painful. Experienced programmers actually like the validation process because it becomes much easier and prevents problems that could cause lots of grief later.
This little code snippet does a bunch of neat things, such as
♦ Establishing your coding prowess: Any page that has this image on it has been tested and found compliant to XHTML Strict standards. When you see pages with this marker, you can be confident of the skill and professionalism of the author.
♦ Placing a cool image on the page: You’ll read how to add your own images in Chapter 6 of this minibook, but it’s nice to see one already. This particular image is hosted at the W3C site.
♦ Letting users check the page for themselves: When the user clicks the image, they’re taken directly to the W3C validator to prove that the page is in fact valid XHTML Strict. Unfortunately, this link works only on pages that are posted to a Web server, so it doesn’t work correctly on a page just sitting on your computer. Scope out Book VIII for suggestions on finding and using a server.
Using Tidy to repair pages
The W3C validator isn’t the only game in town. Another great resource — HTML Tidy — can be used to fix your pages. You can download Tidy or just use the online version at http://infohound.net/tidy. Figure 2-12 illustrates the online version with oxWheels1.html being loaded.
Figure 2-12: HTML Tidy is an alternative to the W3C validator.
Unlike W3C’s validator, Tidy actually attempts to fix your page. Figure 2-13 displays how Tidy suggests the oxWheels.html page be fixed.
Figure 2-13: Tidy fixes the page, but the fix is a little awkward.
Tidy examines the page for a number of common errors and does its best to fix the errors. However, the result is not quite perfect:
♦ Tidy adds a new meta tag, indicating the page was created by Tidy. I always get nervous when a program I didn’t write starts messing with my pages.
♦ Tidy tends to choose a sloppier doctype. If you don’t specify otherwise, Tidy checks against XHTML 1.0 Transitional, rather than Strict. This definition isn’t as stringent. You can (and should) specify the Strict doctype manually in the submission form.
♦ Tidy got confused by the title. Tidy correctly diagnosed the title in the wrong place, but it added a blank title, as well as the intended one.
♦ Sometimes, the indentation is off. I set Tidy to indent every element, so it is easy to see how tag pairs are matched up. If I don’t set up the indentation explicitly, I find Tidy code very difficult to read.
♦ The changes aren’t permanent. Anything Tidy does is just a suggestion. If you want to keep the changes, you need to save the results in your editor.
I sometimes use Tidy when I’m stumped because I find the error messages are easier to understand than the W3C validator. However, I never trust it completely. There’s really no substitute for good old detective skills and the official W3C validator.
If you find the W3C validator and Tidy to be a little tedious to use, look over the HTML validator extension described in Chapter 3 of this minibook. This handy tool adds both the W3C validator and Tidy to Firefox and automatically checks every page you visit. It also has Tidy support, so it can even fix most of your errors. That’s how I do it.
Chapter 3: Choosing Your Tools
In This Chapter
Choosing a text editor
Using a dedicated HTML editor
Comparing common browsers
Introducing Integrated Development Environments (IDEs)
Adding important Firefox extensions
Web