I Got Them Code-Won’t-Validate Blues

It’s very frustrating when you try to validate an XHTML file and either the validator says it can’t make sense of your file and gives up or it gives you dozens upon dozens of error messages.  Fortunately, the problems are usually solved pretty easily.  Here are some of the most common reasons for problems:

  • Prolog problems.  The validator relies on the prolog to know exactly which flavor of (X)HTML to validate your code against.  If there’s a problem with the prolog, the validator can’t do its thing.  So make sure all three lines (the XML and Doctype declaratations and the html tag with xmlns) are exactly correct.  A single mistyped character is enough to throw the whole thing off!  In particular, be careful of case-sensitivity, and with the word xhtml1, make sure you’re clear about what’s an “L” and what’s the digit ONE.
  • Embedded spaces.  Space characters are never valid within a URL, so make sure that you don’t use spaces in the names of any of your HTML files or bookmark anchors.  I generally prefer to keep file names and anchor names short, but if you feel that you need a long one, name it like one of these:  FileWithALongFilename.htm or file_with_a_long_filename.htm or file-with-a-long-filename.htm.
  • Invalid characters.  If the validator sees a character that is not part of the encoding character set (probably specified in your xml declaration, otherwise maybe defaulting to “UTF-8”), it will reject the entire file — but it will give you the line and column number of the offending character.   If you need to use foreign accented characters, be sure to code them with the proper HTML character entities.  Also, be careful if you copy-and-paste from another source — programs such as MS Word will convert your typed apostrophes and quotation marks into “smart quotes”, which are invalid characters to the validator.
  • Use of the font tag.  Remember that the font tag is an inline element.  The validator doesn’t like to see an inline element wrapped around block-level elements (such as heading, p, ul tags).  So if you want to change the font for everything within an ordered list, for example, put a <font> ... </font> pair inside each <li> ... </li> pair.  Yeah, it’s a nuisance, which is why they developed Cascading Style Sheets as a better alternative.

Remember that we talked about the general process of validation at our third class session.  You might want to review my slides at www.nvcc.edu/home/tgutnick/itd110/slides/03c-Validation.pdf and your own notes.  You did take notes while I talked, didn’t you?

Happy validating.