1.12 Well-formed XML
All XML must be well formed. A well-formed XML document is one in which, in addition to all the constructs being syntactically correct, there is exactly one top-level element, all open tags have a corresponding close tag or use the empty element shorthand syntax, and all tags are correctly nested (that is, close tags do not overlap). In addition, all the attributes of an element must have different names. If attributes are namespace qualified then the combination of namespace name and local name must be different. Similarly, all the namespace declarations of an element must be for different prefixes. All namespace prefixes used must have a corresponding namespace declaration that is in scope.
Examples
Well-formed XML
<?xml version='1.0' encoding='UTF-8' ?> <p:Person xmlns:p='urn:example-org:People' > <name>Martin</name> <!-- Young and spritely --> <age>33</age> <height units='inches' >64</height> </p:Person>
A well-formed XML document
XML that is not well formed
<?xml version='1.0' encoding='UTF-8' ?> <p:Person> <name>Martin</name> <age value='33' >A young <b><i>and</b></i> spritely person</age> <height units='inches' units='in'>64</height> <weight xmlns:x1='urn:example-org:People' xmlns:x2='urn:example-org:People' x1:units='stone' x2:units='shekels' >10</weight> </p:Person> <p:Person/>
An XML document that is not well formed because it has two top-level elements, the <b> and <i> tags inside the age element overlap, the height element has duplicate unqualified attribute names, the weight element has duplicate qualified attribute names, and the namespace prefix p is not in scope