Table of Contents
As we have mentioned in the previous section, an XML file must be well-formed in order to be processed correctly. XML designers have created a thorough checking method called validation that verifies whether elements of an XML file are well-formed and, furthermore, ensures that their ordering and nesting obey certain rules. These rules are specified by a DTD or an XML Schema. This validation is performed prior to any further processing so that programs that process an XML file do not waste time checking for such errors. An application is even allowed to stop any processing if it encounters an invalid XML file.
The author of an XML file can usually be warned of the invalidity of his XML file at creation time. This validation can be done either within the XML text editor itself (e.g. XMLSpy [3], <oXygen/> [52] or the nXML mode in Emacs [19]) or by an external validator program (e.g. Xerces [4] or XSV [46]). XML editors can also play an active role in the creation of valid XML files, by suggesting at each point valid completions (acceptable elements, attributes or values) depending on the DTD or the XML Schema.
XML, like its ancestor SGML, defines the validation of a file with respect to a Document Type Declaration (DTD) declared at the start of the file. Most often, the DTD is an accompanying external document that allows different files to follow the same rules by sharing it. A DTD is relatively simple to define but the validation rules it can enforce are quite rudimentary because they can only define constraints on the nesting of elements and perform simple checking on values of attributes.
In order to validate the content of elements, XML designers have defined a more elaborate type system called a Schema which can be used in at least two technologies: XML Schema presented in Section 3.2 and RELAX NG described in Section 3.3. On top of these grammar-based validation techniques, we will also present Schematron, a different approach to validation by means of rules that are evaluated on the instance document.