XML 1.0 has two levels of correctness. A well-formed document meets the grammar and every well-formedness constraint (WFC); breaking one is a fatal error that a processor must report, and a processor must not continue normal processing after it. A valid document also matches its DTD, meeting every validity constraint (VC); only validating processors check these, and a validity error is not fatal.
Well-formedness constraints
| WFC | Rule |
|---|---|
| PEs in Internal Subset | Parameter entity references in the internal subset only between declarations |
| External Subset | The external subset must match the extSubset production |
| PE Between Declarations | Replacement text of a parameter entity used between declarations must match extSubsetDecl |
| Element Type Match | An end tag’s name must match its start tag’s name |
| Unique Att Spec | An attribute name appears at most once in a tag |
| No External Entity References | Attribute values may not reference external entities |
| No < in Attribute Values | The replacement text of an entity referenced in an attribute value may not contain < |
| Legal Character | A character reference must be to a legal character |
| Entity Declared | Unless the document has an external subset or parameter entity references and is not standalone, a referenced general entity must be declared |
| Parsed Entity | An entity reference may not name an unparsed entity |
| No Recursion | A parsed entity may not refer to itself |
| In DTD | Parameter entity references may appear only in the DTD |
Beyond the named constraints, any violation of the grammar is also not
well-formed: a missing end tag, < in the wrong place, a bare ampersand,
a duplicate root, an attribute without quotes, and so on.
Validity constraints
| VC | Rule |
|---|---|
| Root Element Type | The name in the DOCTYPE matches the root element |
| Proper Declaration/PE Nesting | Parameter entity text nests properly with declarations |
| Standalone Document Declaration | standalone="yes" is only true if no external declarations affect the document |
| Element Valid | An element matches its declaration: EMPTY, its content model, mixed content, or ANY |
| Attribute Value Type | The attribute is declared, and its value matches the declared type |
| Unique Element Type Declaration | An element type is declared once |
| Proper Group/PE Nesting | Parenthesised groups in content models nest with parameter entities |
| No Duplicate Types | A mixed content model lists each name once |
| ID | An ID value is a Name, and appears once in the document |
| One ID per Element Type | At most one attribute of an element type has type ID |
| ID Attribute Default | An ID attribute is #IMPLIED or #REQUIRED |
| IDREF | IDREF and IDREFS values match the ID of some element |
| Entity Name | ENTITY and ENTITIES values name unparsed entities |
| Name Token | NMTOKEN and NMTOKENS values are name tokens |
| Notation Attributes | NOTATION values match the listed names, and each is declared |
| One Notation Per Element Type | At most one NOTATION attribute per element type |
| No Notation on Empty Element | An element declared EMPTY has no NOTATION attribute |
| No Duplicate Tokens | A notation or enumeration list has no repeats |
| Enumeration | The value is one of the listed tokens |
| Required Attribute | A #REQUIRED attribute is present |
| Attribute Default Value Syntactically Correct | A default matches the attribute’s type |
| Fixed Attribute Default | A #FIXED attribute, if given, equals its value |
| Proper Conditional Section/PE Nesting | Conditional section markers nest with parameter entities |
| Entity Declared | Where the WFC of that name does not apply, a referenced entity must still be declared |
| Notation Declared | An unparsed entity’s notation is declared |
| Unique Notation Name | A notation name is declared once |
The viewer on this site reports well-formedness errors as fatal, and lists validity problems without rejecting the file, whenever a document’s DTD is complete inside it.