A.2 Well-Formed XML

For an XML document to be considered valid, it must satisfy the following restrictions:

  • The document must have only one top-level element. This element is called the root element.

  • Every element must have both a start and an end tag.

  • All attributes must have values, and those values must be quoted.

  • Elements must not overlap. You cannot use <a><b></a></b>, because the ending </a> tag comes before </b>.

  • You must convert &, <, and > to their entity equivalents. You can use htmlentities( ) to solve this.

When a document meets these rules, it's valid, or well-formed, XML.