1. Home
  2. Computing & Technology
  3. Web Design / HTML

Well Formed XHTML and XML
Part 1: What Does it Mean for a Document to be Well Formed?

By , About.com Guide

When you start writing XML, you will hear over and over the two terms "well formed" and valid. They are not the same thing. You can have a well formed XML document that is not valid, and a valid document that is not well formed. Basically, a well formed document is one that meets the minimum criteria for XML processors and validators to read the document.

An XML document consists of text, but the text forms two different things:

  • markup
    The tags, comments, character, and entity references.
  • character data
    the information and text within the document

When writing well formed XML documents, there are some specific rules you should follow:

  • the XML declaration must come first in every document
  • comments are not valid within a tag
  • comments may not contain two hyphens in a row, other than the beginning and end of the comment
  • tags must have an end tag, or be closed within the singleton tag itself, for example <br />
  • all attributes of tags must be quoted, preferably double quotes unless the attribute itself contains a double quote
  • every XML document must contain one element that completely contains all the other elements

You will find that most of the rules that apply to well formed XML also apply to HTML, well XHTML that is. This is because XHTML is HTML that is rewritten to XML specifications.

Next page > Creating Well Formed HTML > Page 1, 2

Previous Features

Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. About.com Web Design A to Z
  5. Web Design Articles R-Z
  6. Web Design/HTML Articles W
  7. Well Formed XHTML and XML>

©2009 About.com, a part of The New York Times Company.

All rights reserved.