1. Computing & Technology

Discuss in my forum

validate

By , About.com Guide

Definition:

When you validate a web language like HTML, XML, or CSS, you are checking it against the standard for that language. In most cases, the standard you want to validate against is defined at the top of the document in the DTD. For example, to write a valid HTML 4 document you need to have the following doctype at the top of your document:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

This tells the browser or other user agent that you are writing HTML 4.01 Transitional HTML. And if you validated it in an HTML validator, that is the doctype or DTD that the validator would check it against.

How to Validate HTML, CSS, and XML

The easiest way to validate HTML and CSS is to use an online validator. Most web browsers do not check that the HTML or CSS is valid before attempting to render it. But it is still important to write valid HTML and CSS because invalid code can introduce errors and inconsistencies in how your pages are rendered.

You can also validate your XML using an online tool like the W3C validator, but if your XML doesn't have a doctype defined, it will only verify that your document is well-formed, and not if it is valid or not.

This may seem confusing, but it makes sense if you think about it. Validating a web document is checking it against a pre-defined standard. If you don't define what standard you are using for your XML, there is nothing to validate against.

The other way to validate an XML document is with a validating parser. This is an XML user agent that checks the XML against its DTD. If there is no DTD defined, then a validating parser will just make sure the XML is well-formed.

©2012 About.com. All rights reserved.

A part of The New York Times Company.