eWebProgrammer eweb  

XML Programming  «Prev  Next»
Lesson 2Requirements for XML documents
Objective Describe the Concepts of well-formedness and Validity

Describe Well-formedness and Validation Concepts used when Creating XML Documents and Programming

The XML specification defines a set of rules that XML documents must follow in order to be well-formed. If an XML document is not well-formed according to the XML specification, browsers, for example, should not make any attempt at correcting the errors as they did for HTML documents. The inevitable result of browsers correcting HTML documents was the creation of many versions of HTML.

Well-formedness constraint

The following text demonstrates a complete, well-formed XML document:
<greeting>Hello, World!</greeting> 
This XML document is not large, but it is error free.
For reasons of forward compatibility, one additional element is requested, but not required, at the start of XML documents: the xml declaration that specifies the version of XML to which the document conforms. The following example begins with an xml declaration providing version information.
<?xml version="1.0"?> 
<greeting>Hello, World!</greeting> 

What exactly is an XML document? Consider the definition from the W3C's Recommendation for XML 1.0.

Validity constraint

An XML document is valid if it complies with a Document Type Definition (DTD).
A DTD is a text-based file that specifies, among other things, which elements are used in an XML document. An XML parser will validate the XML document against the specified DTD and will generate errors if there are any inconsistencies.

The dichotomy of well-formedness and validation
The dichotomy of well-formedness and validation
The next lesson defines the rules for constructing well-formed XML documents.