Rules for XML Languages

There are nine basic rules for building good XML:

  1. All XML must have a root element. [This element begins and ends your entire document.]
  2. All elements must have an opening tag and a closing tag.
  3. All elements must be properly nested. [Close your elements in the reverse order you opened them. I.e., close the most recently opened element before closing elements opened earlier.]
  4. Element names must not start with a number, a punctuation mark, or the string XML.
  5. Element names are case sensitive.
  6. Element names cannot contain spaces. [If you want to use multiple words in the element name, use camelCase: <placeName>.]
  7. Attribute values must appear within quotation marks (“”).
  8. Don’t type spaces unless they are meaningful. [Space is significant. If you type a space, the processor will usually retain it.]
  9. Optional: avoid HTML tags. [Some XML languages do adopt HTML tags. TEI-XML uses <hi>, <p>, and <li>.

A markup language that conforms to these rules is well formed … or XML-compliant.