XML Validation

Validation is an important feature of XML that allows one to verify that a particular structure conforms both to the syntax and the semantics of a DTD or an XML Schema. This insures that: Validation consists of determining that the XML structure is both. well-formed and valid. Well-formed means that it conforms to a strict tree structure, such that there are no overlapping elements, each element has one parent node, etc. Valid means that it conforms to the exact specifications of the DTD or schema. For example, the following document is not well formed:

<SHAPE> rect <SIZE> </SHAPE> 3x8 </SIZE>

because the elements overlap. However, if the DTD defines the elements SIZE and SHAPE, this document fragment is well-formed but not valid:

<Shape> rect <Size> 3x8 </Size> </Shape>

because, although the elements are properly nested, all definitions are case sensitive and "SHAPE" does not equal "Shape" nor does "SIZE" equal "Size" according to the DTD.

Validating XML Files Defined by DTDs

A DTD largely controls the syntax and semantics of an XML file by: A validation program reads in both the XML and the controlling DTD and then determines whether or not any of these rules are violated: if so it can print out a message that pinpoints the first of these errors in terms of line and character number, the offending line, and a message about the error type.

Validating XML Files Defined by XML Schemas

XML Schemas offer the same control as DTDs along with the following extensions (not all of which, however, are implemented at this time):

This program will validate any XML file defined by a DTD or an XML Schema.