Articles, Tips

Top Validation Errors When Using XHTML

August 28, 2009 • By

As a developer being able to write valid XHTML code is one of the most sought out requirements. Valid XHTML can be a daunting obstacle to overcome if the developer is either in-experienced or has little or no knowledge dealing with code. Improperly placed elements, and incorrectly nested characters can prolong the inevitable work of coding a website.

Many times after your website seems to be complete, there are several errors that can be found throughout your designs structure. This is why a series of trial and error topped with extra careful code can limit the mistakes found by your visitors once the site is up and running. Within this article you will find top XHTML mistakes that can be passed up if you’re not paying attention. We’ve also provided you with a custom solution on how to fix each and every error encountered below.

validation-01

Improperly Terminating an Entity

Example: Foo “&amp” Bar

Validator Result: reference not terminated by REFC delimiter

Solution: You simply created an entity and you forgot to terminate it with a semi-colon, like Foo “&” Bar. In order to fix this, just add a semi-colon to terminate the entity.

Violating the Naming Convention of an Attribute

Example: <a href=”http://www.foobar.com” name=”1″>Foo Bar</a>

Validator Result: character X is not allowed in the value of attribute Y

Solution: The name attribute like the id attribute must begin with a letter, not a number. <a href=”http://www.foobar.com” name=”foo”>Foo Bar</a> .

Using Uppercase Characters in Markup Tags

Example: <BODY> </BODY>

Validator Result: element “BODY” undefined. Did you mean “body”?

Solution: This error is fairly easy to correct. Many times it’s easy to forget to press the caps lock and this seems to happen. If you don’t use the cap sized letters this will cause your markup to display incorrectly. This is one of the easiest errors to overlook.

Not Specifying a Document Type Definition

Example: <!DOCTYPE PUBLIC “…

Validator Result: no document type declaration; will parse without validation

Solution: Your document does not have a document type declaration which should look like this: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>.

validation-02

Having a Closing Tag for an Element Without an Opening Tag

Example: <p>…</p></div>

Validator Result: end tag for element X which is not open

Solution: It’s possible that throughout the time that you were editing your code, you left an uneeded closing tag. All you have to do is delete the closing tag if you don’t need it any more. <p>…</p> .

validation-03

Incorrectly Nested Elements

Example: <p><em>…</p>

Validator Result: End tag for X which is not finished

olution: This is a pretty simple error to fix. Your <em> tags needs to be closed before the closing paragraph tag, like this <p><em>…</em></p> .

Forgetting to Wrap Your Text in a Tag

Example: This is a paragraph

Validator Result: character data is not allowed here

Solution: Remember to always wrap you text in a tag, the correct code would be <p>This is a paragraph</p> .

Not Escaping Special Characters

Example: <p>I develop websites using XHTML & CSS.</p>

Validator Result: character X is the first character of a delimiter but occurred as data

Solution: It’s mostly safer to ensure that you encode the ampersand character in XHTML as “&amp;” This is also very important for using angled brackets. For example “<” should be encoded as “&lt;” .

Using Incorrect Syntax for Comments

Example: <!–comment>…<!–comment–>

Validator Result: invalid comment declaration: found character X outside comment but inside comment declaration

Solution: You have to close the first comment tag. This can act as blockade if you have a lot of comments in your code, but its fairly easy to fix with the help of the validator.

validation-04

Forgetting the Inclusion of Quotation Marks (Around the Values for Attributes)

Example: <td rowspan=8></td>

Validator Result: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified

The Solution: Once you begin utilizing attributes, their values must be enclosed in quotation marks. For instance, <td rowspan=”8″></td> .

Can you think of anymore XHTML errors that we weren’t able to discuss above? If so, please fee free to share with us!

(Visited 205 times, 1 visits today)