When an XML file is correctly formatted with proper syntax, it is said to be well formed.
Consider the following well formed XML document.
A Christmas Carol "Charles Dickens" Fiction 1843 86 A Treatise on Government Aristotle Non-Fiction 322 195 A Thief in the Night E. W. Hornung Short Stories 1905 182
This document is considered well formed because it follows XML syntax rules. It has a root element, all elements are properly nested, and each element tag is properly closed. In addition, all attributes are in quotes, and the CDATA tag is correctly formatted.
When an XML file contains a DTD (document type definition) and adheres to that DTD, it is said to be valid. A valid XML file must also be well formed.
Consider the following valid XML document.
]> A Christmas Carol Charles Dickens Fiction 1843 86 A Treatise on Government Aristotle Non-Fiction 322 195 A Thief in the Night E. W. Hornung Short Stories 1905 182 Some Book &unknown; Non-Fiction 500 1000
In this example, the DTD is included in the XML. It could just as easily be included as an external file.
The rules of this DTD are as follows:
Each book element must contain the children title,author,genre,year,pages.
They must also appear in that order.
All elements except 'link' may only contain parsable data. CDATA may not be used.
The element 'year' must have an attribute for 'era', and will default to "AD"
&unknown;
You might also be interested in





