Well Formedness and Validation

Well-formedness

All XML documents, whether you make up your own elements or use an established XML language, must consist of a well-formed XML hierarchy (i.e., tree structure). 

  • The entire tree must be rooted on a single root element. (I.e., the entire document is contained within that element.)
  • Elements must be correctly nested. (I.e., child elements have to be closed before the parent element is closed.)

Validation

To be valid, an XML document must be well-formed AND must follow the rules of a particular XML language (like BeerXML, TEI-XML, or DocBook). 

  • It must use the elements and attributes that are allowed by that language (i.e., allowed in that namespace).
  • It must use them in the right order.
  • It must supply the required children elements for each parent.
  • It must supply any required sibling elements.
  • It must use the attributes that are required or optional for each element (if any).

The rules of the language can be set out in documentation (like BeerXML) and/or in a schema